Skip to content
Latchkey

Terraform "Saved plan is stale" - Plan No Longer Matches State in CI

You saved a plan in one job and applied it in another, but the state changed in between. Terraform rejects the saved plan because applying it would no longer be safe.

What this error means

terraform apply tfplan in a separate job fails saying the saved plan is stale - the state has a different serial than when the plan was created. It happens when another run (or a manual change) touched state between plan and apply.

terraform apply output
Error: Saved plan is stale

The given plan file can no longer be applied because the state was changed by
another operation after the plan was created.

Diagnose it: init, state, or credentials?

Terraform failures in CI are dominated by backend and credential problems rather than configuration errors. Confirm the runner can initialise, authenticate, and lock state before reading the plan.

Terminal
terraform init -backend=true -input=false
terraform validate
terraform providers
terraform plan -input=false -no-color -detailed-exitcode
#   0 = no changes, 2 = changes, 1 = error

Common causes

State changed between plan and apply

Another apply, a drift, or a manual edit advanced the state serial after the plan file was written, so the saved plan no longer matches reality.

Long gap or no serialization between jobs

A manual approval gate or unserialized pipelines let another run modify state during the wait, invalidating the saved plan.

How to fix it

Re-plan and apply against current state

Generate a fresh plan immediately before applying so it matches the current state.

Terminal
terraform plan -input=false -out=tfplan
terraform apply -input=false tfplan

Serialize plan and apply

Use a CI concurrency group so no other run mutates state between the plan and apply jobs.

.github/workflows/ci.yml
concurrency:
  group: terraform-${{ github.ref }}
  cancel-in-progress: false

How to prevent it

  • Keep the gap between plan and apply short, and re-plan if it grows.
  • Serialize Terraform runs with a concurrency group.
  • Treat a stale-plan error as a signal to re-plan, never to bypass.

Frequently asked questions

What causes Terraform "Saved plan is stale"?
There are 2 common causes: state changed between plan and apply and long gap or no serialization between jobs. Another apply, a drift, or a manual edit advanced the state serial after the plan file was written, so the saved plan no longer matches reality.
How do I fix Terraform "Saved plan is stale"?
There are 2 fixes depending on which cause you have: re-plan and apply against current state and serialize plan and apply. Work through them in order, since the first is the most common.
What does Terraform "Saved plan is stale" actually mean?
terraform apply tfplan in a separate job fails saying the saved plan is stale - the state has a different serial than when the plan was created.
How do I stop Terraform "Saved plan is stale" happening again?
Keep the gap between plan and apply short, and re-plan if it grows. The prevention section lists 3 changes that keep it from recurring.

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card