Saved plans and stale changes
Review the exact plan that will be applied
Running apply without a saved plan creates a fresh proposal and normally asks for confirmation. Saving a plan makes it possible to review the particular proposal that will be submitted later. In this chapter the catalog fixture uses a local backend only; remote execution has different details. The following sequence is for an approved disposable copy, not a production directory.
terraform plan -out=review.tfplanterraform show review.tfplan# Only after explicit approval of this exact plan:terraform apply review.tfplanPassing a saved plan to apply is itself approval from Terraform’s perspective: it does not ask for interactive confirmation. The comment is a human approval gate, not a command that enforces authorization. In a team, enforce that gate through access controls and an approval record tied to the exact protected artifact. Do not pass new planning flags or variable values when applying a saved plan.
Read a replacement in machine-readable form
The release fixture uses a synthetic revision to request replacement when its value changes.
variable "revision" { type = number default = 1}
resource "terraform_data" "release" { input = "catalog" triggers_replace = var.revision}After applying revision 1 in an approved local copy, plan revision 2 with terraform plan -var="revision=2". Expect a replacement, not simply a change of the displayed label. A saved local plan can be inspected with terraform show -json review.tfplan; do not run this on real plans for this course. The following is a deliberately incomplete invented change object, not actual output or a complete schema.
{ "address": "terraform_data.release", "change": { "actions": [ "delete", "create" ], "after_unknown": { "id": true } }}The actions array preserves the operation order. A true flag at after_unknown.id indicates the ID is not yet available. For actual tooling, validate the documented format version, handle unfamiliar action sequences by stopping for review, and do not confuse a stream of CLI JSON events with a plan JSON document. Sensitive markers help a consumer redact displays; underlying values may still be present.
Protect saved plans and approval records
A saved local plan can contain configuration, input values, backend settings and sensitive data. Limit access and retention as for state, never commit it, and do not attach it to tickets or chat. Record only approved metadata such as an internal change identifier, reviewed artifact digest and intended environment. A digest identifies bytes but is not authorization, encryption or proof of correctness. Keep the matching toolchain and environment; do not assume plans can be transferred across versions or unrelated workspaces.
When a plan must be replaced
Suppose reviewer A approves a plan from one state snapshot. Operator B then performs a different approved change that updates the same state. The original saved plan may be rejected as stale. Stop, inspect the current authorized context, regenerate a plan and obtain fresh approval. Even if Terraform accepts a plan, changed external conditions may invalidate assumptions, so do not equate state freshness with live infrastructure freshness. Avoid parallel writers; supported backend locking reduces overlapping state operations but is not a substitute for review or drift detection.
A failed apply is not an automatic rollback
A fictional plan contains two independent creates. One succeeds and the other fails due to a provider error. The successful object may remain, and Terraform may record its result in state. Do not assume the previous environment was restored or repeat the old plan blindly. Preserve diagnostics securely, confirm actual objects and state using authorized narrow inspection, resolve the underlying failure and make a new plan for the remaining work. Escalate uncertain ownership or state persistence failures to the responsible operator. Recovery may require a separate reviewed action and application data restoration; neither is guaranteed by Terraform.
Finish the local practice safely
Review the release fixture and the synthetic decision cases. In a fresh local copy only, optionally save and inspect a plan, then apply only after explicit approval. To demonstrate stale-plan detection, create a saved change plan for one label, then apply a different reviewed label change in the same disposable catalog directory. Attempt the old saved plan only in this isolated exercise; expect rejection after the state changes. Never bypass a stale-plan error. Re-plan and review. For cleanup preview destroy and approve only the lab resources. No native commands were executed during authoring.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Saved plans and stale changes — knowledge check
Review proposed changes and saved-plan approval.
What happens when apply receives a saved local plan?
What is the appropriate response to a stale saved plan?
Which statement about saved plans is correct?
What does after_unknown identify in a plan JSON change?
What should you assume after one operation succeeds and a later apply operation fails?