Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 772 of 80211. Production Operations and ReliabilityFree lesson

Executing Safe Infrastructure Changes with Plan Previews

Adopt a workflow that requires reviewing execution plans to visualize resource modifications before applying changes to live production infrastructure.

In this lesson, you will learn how to mitigate the risks of production downtime by using infrastructure execution plans to visualize and verify resource modifications before they are applied.

The Danger of "Blind" Infrastructure Changes

When managing infrastructure as code (IaC), a simple configuration error—such as a typo in a load balancer rule or an accidental deletion of a persistent volume—can lead to catastrophic production outages. Because infrastructure is declarative and often manages state, applying changes blindly is akin to deploying code without unit tests. To ensure reliability, we must shift the verification process to a "plan-first" workflow.

Visualizing State Changes

Modern IaC tooling provides a plan phase, which compares your desired state (the code) against the current live state (the remote backend). This process generates a preview of the specific create, update, or delete operations that will occur.

For example, when using Terraform or similar declarative frameworks, you should integrate the following command into your CI/CD pipeline:

# Generate the execution plan and save it to a file
terraform plan -out=tfplan

# Review the plan output
terraform show tfplan

The "Plan-Apply" Workflow

By enforcing a structured workflow, you prevent manual interference. In your CI/CD pipeline, the job responsible for modifications should be split into two distinct stages:

  1. The Review Stage: The pipeline computes the plan, saves it as an artifact, and halts execution. This forces a human operator to review the diff.
  2. The Approval Stage: Only after an authorized engineer verifies that the modifications match the intended business logic is the apply command triggered using the pre-generated plan file.

This process ensures that your infrastructure changes are deterministic. If the plan shows an unexpected replacement of a production database, you catch the error during the PR review process rather than witnessing a data-loss event in real-time. By treating infrastructure changes with the same rigor as application code reviews, you maintain the stability of your production environment.

Key Takeaway: Never execute infrastructure modifications against production without first generating, reviewing, and approving an explicit execution plan to visualize exactly what will change.