Skip to content
Latchkey

Terraform "Saved plan is stale" - Fix plan/apply Drift in CI

You applied a saved plan file, but the state changed since that plan was created. Terraform refuses to apply a plan built against an older state to avoid acting on stale assumptions.

What this error means

terraform apply tfplan fails saying the saved plan is stale or no longer valid, typically because another run modified state between the plan and apply jobs of a pipeline.

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.

Common causes

State changed between plan and apply

In a split plan/apply pipeline, another apply (or a drift) modified state after the plan file was written, invalidating it.

Concurrent runs racing the same state

Two pipelines plan and apply against the same state without serialization, so one’s apply lands on state the other already moved.

How to fix it

Re-plan immediately before apply

Regenerate the plan in the same job (or right before apply) so it matches current state.

.github/workflows/ci.yml
terraform plan -input=false -out=tfplan
terraform apply -input=false tfplan

Serialize Terraform runs

Prevent concurrent applies against the same state with a CI concurrency group so a saved plan cannot be raced.

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

How to prevent it

  • Serialize Terraform jobs with a concurrency group.
  • Keep the plan→apply window short, ideally in one job.
  • Use backend locking so concurrent writers cannot race the state.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →