DevOps & Agile Fundamentals

Chapter 8
Infrastructure, Cloud and Deployment Automation

Certificate in DevOps
DevOps & Agile Fundamentals   •   Certificate

Infrastructure, Cloud and Deployment Automation

Introduction

Modern software is delivered through a chain of environments, including developer workstations, continuous integration systems, test platforms, staging systems and production. If these environments are created manually, they gradually diverge. Differences in operating-system packages, network rules, credentials, runtime versions and configuration can cause an application to succeed in one environment and fail in another. DevOps addresses this problem by treating infrastructure and deployment as repeatable, automated and observable engineering activities.

This chapter examines infrastructure as code, configuration management, cloud service models, containers and orchestration. It also develops three closely related principles:

  • Reproducibility: the same declared inputs should produce substantially the same result.
  • Immutability: deployed artifacts should be replaced rather than modified unpredictably in place.
  • Environment consistency: development, testing and production should differ deliberately and minimally.

These principles do not mean that every environment must be identical. Production may require greater capacity, stronger controls and different data-protection arrangements. The goal is to ensure that differences are explicit, version-controlled and understood.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Explain infrastructure as code and distinguish it from configuration management.
  2. Describe declarative and imperative automation approaches.
  3. Compare infrastructure, platform and software as a service.
  4. Explain how containers package applications and why orchestration is required at scale.
  5. Apply reproducibility, immutability and environment-consistency principles to a deployment scenario.
  6. Identify security, governance and operational risks in automated infrastructure.

1. Infrastructure as Code

Infrastructure as code (IaC) is the practice of defining infrastructure resources—such as networks, virtual machines, databases, identity policies and load balancers—in machine-readable files that can be reviewed, versioned and applied automatically. Instead of recording that “an engineer created a server and changed several settings,” an IaC repository records the desired infrastructure configuration.

IaC usually contains four elements:

  1. Resource definitions: what should exist, such as a virtual network or database.
  2. Parameters: values such as region, instance size and replica count.
  3. Relationships: dependencies between resources, for example an application requiring a database endpoint.
  4. State or evidence: information about what has already been provisioned and whether actual infrastructure matches the declaration.

Declarative and imperative approaches

A declarative approach states the desired end state. The automation tool determines which operations are necessary to reach it. A declaration might specify that a service must have three instances, encrypted storage and a private network connection.

An imperative approach specifies the sequence of commands to execute: create a network, create a subnet, create a firewall rule and then create a server. Imperative scripts can be useful for procedural tasks, but repeated execution may produce duplicate or inconsistent results unless the script is carefully designed to be idempotent.

Idempotence means that applying an operation repeatedly has the same effective result as applying it once. For example, “ensure that the package is installed at version 2.4” is idempotent; “install the package” may not be, because repeated execution could fail or produce an unintended version.

Declarative systems commonly use a reconciliation model:

  • desired state is read from code;
  • actual state is inspected;
  • the difference is calculated;
  • permitted changes are applied;
  • the result is checked.

This model supports drift detection. Configuration drift occurs when the actual environment changes without a corresponding change in the authoritative definition. Drift may be caused by emergency manual changes, automatic provider updates, unrecorded scripts or compromised credentials.

Version control and review

IaC should be stored in a version-control system. A change to a firewall rule or database access policy deserves the same review discipline as a change to application code. Useful practices include pull requests, automated validation, peer approval, change history and controlled promotion between environments.

A mature IaC workflow separates:

  • reusable modules, such as a standard encrypted database;
  • environment-specific values, such as capacity or region;
  • secrets, which should normally be retrieved from a secure secret-management system rather than committed to source control;
  • policy checks, such as prohibiting public storage buckets or unrestricted administrative ports.

IaC does not remove the need for architectural decisions. It makes those decisions more visible, repeatable and auditable.

2. Configuration Management

Configuration management focuses on ensuring that systems have the required software, files, services and settings. It may configure operating systems, install packages, create users, place application configuration files, manage services and enforce security baselines.

IaC and configuration management overlap but are not identical. IaC commonly provisions the infrastructure boundary—networks, compute resources and managed services—whereas configuration management often prepares the operating system and application runtime inside those resources.

ConcernTypical questionExample
Infrastructure provisioningWhat resources should exist?Should a private subnet and database be created?
Configuration managementHow should a host be configured?Which packages, users and service settings are required?
Application deploymentWhich application version should run?Should release 4.8.2 replace release 4.8.1?
Policy and complianceWhat must never occur?Is public access to an encrypted database prohibited?

Configuration management can be agent-based, where software runs on each managed host, or agentless, where a controller connects remotely. Both approaches require secure authentication, controlled privileges and reliable inventories.

A useful operational distinction is between configuration data and secrets. Configuration data may include a service port or feature flag. Secrets include passwords, private keys, tokens and certificates. Secrets require restricted access, encryption, rotation and audit logging. Encoding a secret in a configuration file is not the same as protecting it.

3. Cloud Service Models and Deployment Models

Cloud computing provides on-demand access to computing resources, commonly with elastic capacity, network access, pooled infrastructure and usage-based charging. Cloud services reduce the need to purchase and operate every physical component, but they do not eliminate responsibility. They redistribute responsibility between the provider and customer.

Service models

Infrastructure as a Service (IaaS) provides fundamental resources such as virtual machines, storage and networks. The customer generally manages the operating system, applications, data and many security settings. IaaS offers control but requires significant administration.

Platform as a Service (PaaS) provides a managed runtime or application platform. The provider typically manages more of the operating system and platform, while the customer supplies application code, configuration and data. PaaS can accelerate delivery but may constrain runtime choices and create migration considerations.

Software as a Service (SaaS) delivers a complete application to users. The provider manages the application and underlying platform. The customer remains responsible for appropriate use, identity management, data governance and organizational controls.

ModelCustomer commonly managesProvider commonly manages
IaaSOS, applications, data, much configurationPhysical infrastructure and virtualization
PaaSApplication code, data, access policiesOS, runtime platform and infrastructure
SaaSUsers, data use, configuration and governanceApplication, platform and infrastructure

The exact division varies by provider and service. A “managed” service is not automatically secure; customers can still configure weak identities, expose data or neglect backup and retention requirements.

Cloud deployment models include public cloud, private cloud, hybrid cloud and, in some organizations, multicloud. A hybrid arrangement connects private infrastructure with public-cloud resources. Multicloud may reduce dependence on one provider or meet geographic and regulatory requirements, but it increases integration, skills and operational complexity.

Capacity and elasticity

Cloud automation often uses elasticity: capacity increases or decreases in response to demand. Scaling can be vertical, by changing the size of a resource, or horizontal, by changing the number of service instances. Horizontal scaling generally supports resilience more effectively for stateless services, but it requires suitable load balancing, session handling and data design.

Cost is an engineering constraint. An automated system that creates unused resources, excessive logs or unnecessary replicas may be technically successful but financially poor. Tagging, budgets, quotas, lifecycle policies and regular cost review are therefore part of responsible cloud operations.

4. Containers and Images

A container packages an application and its user-space dependencies into an isolated execution unit. Unlike a traditional virtual machine, a container commonly shares the host operating-system kernel while maintaining process, filesystem and network isolation through operating-system mechanisms. Containers are therefore usually lighter and faster to start than full virtual machines, although they are not a complete security boundary in every situation.

A container image is an immutable package used to create containers. It commonly consists of layered filesystems and metadata describing the startup command, environment and exposed interfaces. A container registry stores and distributes images.

A sound image-building process should:

  • begin with a trusted, minimal base image;
  • pin or otherwise control dependency versions;
  • avoid embedding credentials;
  • run the process as a non-root user when feasible;
  • remove unnecessary tools and files;
  • scan dependencies and image contents for vulnerabilities;
  • attach provenance, version information and ideally a cryptographic signature.

A container is not automatically immutable merely because it is packaged as an image. Operators can still modify a running container. The stronger practice is to treat running containers as disposable and rebuild an image when code or system dependencies change.

Containers also have limitations. They share kernel resources, can be misconfigured with excessive privileges, and may conceal operational complexity. Persistent data should normally be stored in a suitable managed storage system rather than in the writable layer of a disposable container.

5. Orchestration

Running one container manually is simple. Operating hundreds of replicas across hosts requires scheduling, service discovery, health checks, networking, secrets handling, rolling updates and recovery. Container orchestration automates these concerns.

An orchestrator typically provides:

  • scheduling: selecting an appropriate host for a workload;
  • desired-state management: maintaining a declared number of replicas;
  • service discovery: allowing workloads to locate one another;
  • health management: restarting or replacing unhealthy instances;
  • scaling: changing capacity in response to policy or demand;
  • deployment strategies: supporting rolling, blue-green or canary releases;
  • resource controls: applying CPU, memory and placement constraints;
  • access control and secrets integration.

A key idea is that an orchestrator continually reconciles desired state with observed state. If a declared service requires three replicas and one fails, the orchestrator attempts to create a replacement. This improves resilience but does not guarantee that the application is correct. A service can remain “healthy” at the process level while returning incorrect business results.

Health checks should therefore distinguish at least two concepts:

  • a liveness check, which asks whether a process should be restarted;
  • a readiness check, which asks whether the service is prepared to receive traffic.

Poorly designed checks can cause restart loops or route traffic to an unready dependency. Observability—logs, metrics, traces and meaningful alerts—is essential for interpreting orchestrator behaviour.

6. Reproducibility, Immutability and Environment Consistency

Reproducibility

A deployment is reproducible when an authorized operator or pipeline can recreate it from known inputs. Inputs include source code, dependency versions, image digests, infrastructure definitions, configuration values and deployment procedures.

Reproducibility is strengthened by:

  • locking dependency versions;
  • using deterministic build steps where possible;
  • recording artifact checksums or image digests;
  • versioning infrastructure and deployment configuration;
  • using the same build artifact across environments;
  • documenting external dependencies and required permissions.

Reproducibility does not imply that every output is bit-for-bit identical. Some resources contain generated identifiers, timestamps or provider-assigned values. The important requirement is that differences are controlled, explainable and operationally acceptable.

Immutability

An immutable deployment model creates a new artifact or environment for a change and replaces the old one. A mutable model modifies a running server in place. Mutable changes can be fast during an emergency, but they are difficult to audit and reproduce. The server may contain undocumented patches or temporary files that disappear when it is replaced.

Immutability supports rollback: if release B fails, traffic can be directed to release A, provided A remains available and compatible with data changes. Database migrations require special care because application rollback and data rollback are not always equivalent. Backward-compatible, additive schema changes are often safer than changes that immediately remove fields required by the previous release.

Environment consistency

The familiar phrase “works on my machine” often indicates environment inconsistency. Consistency can be improved by using common image definitions, automated environment creation, shared dependency specifications and a promotion pipeline.

However, development and production should not share sensitive production data merely to appear consistent. Safer consistency concerns software versions, interfaces, deployment mechanisms and operational assumptions. Data should be synthetic or appropriately anonymized, and access should follow least privilege.

7. Deployment Automation and Delivery Strategies

A deployment pipeline commonly performs the following activities:

  1. validate and build the application;
  2. execute automated tests;
  3. create and scan an artifact or container image;
  4. publish the artifact to a controlled registry;
  5. provision or validate required infrastructure;
  6. deploy to a lower-risk environment;
  7. perform smoke, integration and security checks;
  8. obtain required approval or policy authorization;
  9. release to production using a controlled strategy;
  10. monitor the outcome and support rollback or remediation.

A critical principle is build once, promote many. The exact artifact tested should be the artifact deployed to production. Rebuilding separately for each environment can introduce unnoticed differences.

Common release strategies include:

  • Rolling deployment: replace instances gradually. It uses resources efficiently but may temporarily run two versions.
  • Blue-green deployment: maintain two environments and switch traffic between them. Rollback can be rapid, but the approach may require double capacity.
  • Canary deployment: send a small percentage of traffic to the new version, assess evidence and expand gradually. It reduces exposure but requires reliable metrics and traffic control.

Deployment automation must include failure handling. A pipeline should define what happens when tests fail, health checks deteriorate, capacity is unavailable or a security policy is violated. A rollback plan that has never been tested is an assumption, not a capability.

8. Applied Case: Illustrative Online Retail Deployment

Background

An illustrative online retailer operates a web application, an order service and a relational database. The original environment consists of manually configured virtual machines. Developers use different runtime versions, and production servers are patched directly during incidents.

Problem

Releases frequently fail because test and production environments differ. Recovery is slow because no one can state precisely which packages or configuration values exist on each server. A security review also finds that database credentials are stored in deployment scripts.

Analysis

The main weaknesses are configuration drift, mutable infrastructure, poor secret handling and an unrepeatable release process. Simply placing the existing scripts into a pipeline would automate the same weaknesses. The organization first needs an explicit target design and controlled ownership of configuration.

Approach and solution

The retailer adopts the following approach:

  1. Infrastructure definitions create private networks, load balancing, compute capacity and an encrypted managed database.
  2. A container image defines the application runtime and dependencies.
  3. The image is built once, scanned and stored under a versioned digest.
  4. Non-secret configuration is supplied through environment-specific configuration management.
  5. Database credentials are retrieved at runtime from a managed secret store and rotated according to policy.
  6. A test environment is created from the same infrastructure modules as production, with different capacity and synthetic data.
  7. The pipeline runs unit, integration and security tests before deployment.
  8. Production uses a canary release. Traffic begins with a small percentage, while error rate, latency and order-processing success are monitored.
  9. Failed releases are stopped automatically, and the previous image remains available for rollback.

Outcome

The organization gains a repeatable creation process, clearer audit evidence and a smaller difference between environments. Incidents remain possible—automation cannot eliminate software defects—but recovery becomes faster because the deployment artifact and infrastructure definition are known.

Learning points

The case demonstrates that automation is not merely faster manual work. Its value comes from versioned intent, controlled inputs, security boundaries, observable outcomes and tested recovery. It also demonstrates that infrastructure, application code, data migration and organizational approval must be designed together.

9. Risks, Governance and Professional Practice

Automation can amplify both good and bad decisions. A mistaken IaC change may expose an entire network; a compromised pipeline may distribute malicious software widely. Important controls include:

  • least-privilege identities for engineers, pipelines and workloads;
  • separation of development, test and production permissions;
  • mandatory review for sensitive infrastructure changes;
  • policy-as-code checks for prohibited configurations;
  • encrypted communications and storage;
  • secret rotation and audit trails;
  • vulnerability scanning and timely patching;
  • artifact provenance and software supply-chain controls;
  • backup, restoration and disaster-recovery testing;
  • documented ownership and escalation procedures.

Governance also involves legal and ethical responsibilities. Cloud placement may affect data residency and cross-border transfer obligations. Logs may contain personal information. Automated scaling and monitoring can create unnecessary surveillance or cost. Accessibility, service continuity and equitable user impact should be considered alongside technical efficiency.

Artificial intelligence can assist with configuration analysis, anomaly detection, documentation and incident correlation. It should not be granted unrestricted authority to change production infrastructure without human-defined policies, review and rollback controls. AI-generated infrastructure code must be treated as untrusted until tested for security, correctness and cost.

10. Best-Practice Checklist

A practical implementation should ask:

  • Is infrastructure defined in version control?
  • Are changes reviewed and automatically validated?
  • Are operations idempotent and safe to repeat?
  • Are secrets excluded from source code and images?
  • Is the artifact built once and promoted across environments?
  • Are image contents minimal, scanned and attributable?
  • Are infrastructure and application versions recorded together?
  • Are health checks meaningful and observable?
  • Can a failed deployment be stopped and safely reversed?
  • Are backups and restoration procedures tested?
  • Are cloud costs, permissions and regulatory obligations monitored?
  • Are manual emergency changes reconciled back into the authoritative definition?

Chapter Summary

Infrastructure as code expresses infrastructure in versioned, reviewable and executable form. Declarative IaC describes desired state, while configuration management ensures that hosts and services meet defined requirements. Idempotence and drift detection make repeated automation safer and expose undocumented changes.

Cloud service models distribute operational responsibility differently. IaaS offers control, PaaS reduces platform administration, and SaaS provides a complete application service; in every model, customers retain responsibilities concerning identity, data and governance. Containers package applications consistently, while orchestration manages scheduling, health, scaling, networking and controlled replacement.

Reproducibility depends on known inputs, controlled dependencies and promotion of the same artifact. Immutability reduces undocumented in-place changes and supports rollback, although database evolution requires special care. Environment consistency is achieved through shared definitions and automated creation, not by copying sensitive production data into lower environments.

Effective deployment automation combines testing, artifact management, policy enforcement, observability, release strategies and recovery procedures. Security, cost, compliance and ethical considerations must be designed into the automation rather than added after deployment.

Key Terms

Infrastructure as code: Defining infrastructure resources in machine-readable, version-controlled form.

Configuration management: Maintaining required software, files, settings and services on systems.

Declarative automation: Describing the desired end state rather than every execution step.

Imperative automation: Specifying commands or steps to be executed in a particular sequence.

Idempotence: The property that repeated application produces the same effective result as one application.

Configuration drift: Unplanned difference between declared and actual system configuration.

Reconciliation: Comparing desired and observed state and applying permitted corrective action.

Infrastructure as a Service: Cloud provision of fundamental compute, storage and networking resources.

Platform as a Service: Managed application runtime and platform supplied by a cloud provider.

Software as a Service: A complete application delivered and operated by a provider.

Container: An isolated process environment packaging an application and its user-space dependencies.

Container image: A versioned package from which containers are created.

Container registry: A repository for storing and distributing container images.

Orchestration: Automated management of container workloads and their supporting operations.

Reproducibility: Ability to recreate a deployment from known, controlled inputs.

Immutability: Practice of replacing artifacts or environments rather than modifying them unpredictably in place.

Configuration drift: Unrecorded divergence between intended and actual configuration.

Canary deployment: Gradual release to a small portion of users or traffic before wider rollout.

Infrastructure drift: Difference between IaC-defined resources and actual provider resources.

Policy as code: Machine-enforced rules that validate or restrict technical configurations.

Review Questions

Short Answer Questions

  1. What is infrastructure as code, and why is version control important for it?
  2. Distinguish declarative automation from imperative automation.
  3. What is configuration drift, and how can it be detected?
  4. State one major difference between a container and a virtual machine.
  5. What is the purpose of a readiness check in an orchestrated deployment?

Long Answer Questions

  1. Compare IaaS, PaaS and SaaS in terms of customer responsibility, control and operational effort.
  2. Explain how reproducibility, immutability and environment consistency reinforce one another.
  3. Describe the principal functions of a container orchestrator.
  4. Explain why building one artifact and promoting it across environments is preferable to rebuilding for each environment.
  5. Discuss the security and governance controls required for automated cloud infrastructure.

Analytical / Application Questions

  1. A team manually patches production servers and deploys a newly built package separately to each environment. Identify the resulting risks and propose a transition plan based on IaC, immutable artifacts and controlled promotion.
  2. An orchestrated service reports healthy processes, but users experience failed orders. Explain why process-level health checks are insufficient and propose additional evidence and controls.
  3. Design a release strategy for a customer-facing service where rollback must be rapid but infrastructure cost is constrained. Compare rolling, blue-green and canary deployment before selecting and justifying one approach.

Multiple Choice Questions with Answers

Question 1

Which statement best describes infrastructure as code?

A. A document listing server names after they are created

B. Machine-readable definitions used to provision and manage infrastructure

C. A manual checklist for installing software on laptops

D. A monitoring dashboard showing infrastructure health

Correct Answer: B. Machine-readable definitions used to provision and manage infrastructure

Question 2

What is configuration drift?

A. A planned increase in service capacity

B. A container image vulnerability

C. A difference between declared and actual configuration

D. A method for encrypting cloud storage

Correct Answer: C. A difference between declared and actual configuration

Question 3

Which property means that repeating an operation has the same effective result as performing it once?

A. Elasticity

B. Idempotence

C. Portability

D. Observability

Correct Answer: B. Idempotence

Question 4

In which cloud service model does the customer generally manage the operating system?

A. SaaS

B. PaaS

C. IaaS

D. Managed application service

Correct Answer: C. IaaS

Question 5

Why are containers commonly useful in deployment automation?

A. They guarantee that application code has no defects

B. They package an application with its user-space dependencies

C. They eliminate the need for access control

D. They always provide stronger isolation than virtual machines

Correct Answer: B. They package an application with its user-space dependencies

Question 6

What is a primary function of a container orchestrator?

A. Writing business requirements

B. Scheduling workloads and maintaining desired replicas

C. Replacing all application testing

D. Designing database schemas automatically

Correct Answer: B. Scheduling workloads and maintaining desired replicas

Question 7

Which practice most directly supports the principle of build once, promote many?

A. Rebuilding the application separately in production

B. Using the same versioned artifact across environments

C. Editing production servers manually after deployment

D. Copying production credentials into test systems

Correct Answer: B. Using the same versioned artifact across environments

Question 8

What is the main purpose of a canary deployment?

A. To expose a new release gradually to a limited portion of traffic

B. To delete the previous release before testing

C. To prevent all monitoring during deployment

D. To run only database migrations

Correct Answer: A. To expose a new release gradually to a limited portion of traffic

Question 9

Which item should normally be stored in a secret-management system rather than committed to source control?

A. A service description

B. A public documentation URL

C. A database password

D. A non-sensitive port number

Correct Answer: C. A database password

Question 10

Why is a readiness check different from a liveness check?

A. Readiness determines whether traffic should be sent, while liveness concerns whether a process should be restarted

B. Readiness encrypts data, while liveness compresses logs

C. Readiness applies only to databases, while liveness applies only to networks

D. Readiness creates images, while liveness provisions virtual machines

Correct Answer: A. Readiness determines whether traffic should be sent, while liveness concerns whether a process should be restarted

DevOps & Agile Fundamentals
Chapter 8 of 14