Skip to content
Latchkey

Terraform "Saved plan is stale" when applying a plan file in CI

A common CI pattern is plan -out=tfplan in one job and apply tfplan in another. If the state changed in between, the saved plan no longer reflects the current state and Terraform refuses to apply it as stale.

What this error means

apply of a saved plan file fails with "Error: Saved plan is stale" stating the given plan can no longer be applied because the state was changed by another operation.

Terraform
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

Another apply changed state between plan and apply

A concurrent run or a manual change mutated state after the plan was saved, so the saved plan is out of date.

A long gap let drift or a refresh change the state

Time between the plan and apply stages allowed the recorded state serial to advance, invalidating the plan.

How to fix it

Re-plan, then apply the fresh plan

  1. Regenerate the plan against current state with plan -out.
  2. Apply the freshly created plan file immediately.
  3. Keep plan and apply close together to avoid drift.
Terminal
terraform plan -out=tfplan
terraform apply tfplan

Serialize plan and apply for one state

Gate plan and apply behind a concurrency group so no other run can change state between the two stages.

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

How to prevent it

  • Run plan and apply in the same locked window per state.
  • Avoid concurrent applies against the same backend key.
  • Minimize the delay between saving and applying a plan.

Related guides

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