Terraform "state snapshot was created by ... does not match" in CI
A saved plan embeds the state lineage/serial it was generated against. If the state moved on (another apply ran, or a different CLI version wrote it) before this plan applies, the snapshot no longer matches.
What this error means
apply of a saved plan fails saying the state snapshot does not match, or that the saved plan is stale. It appears when plan and apply are separate CI jobs and the state changed in between.
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. The current state snapshot does not
match the one recorded in the plan.Common causes
State changed between plan and apply
Another apply (CI or manual) modified the state after the plan file was produced, invalidating its recorded snapshot.
Different CLI version wrote the state
A plan and apply run on different Terraform versions can disagree on the state snapshot the plan expects.
How to fix it
Re-plan against current state, then apply
Regenerate the plan from the latest state in the same workflow and apply that fresh plan.
terraform plan -input=false -out=tfplan
terraform apply -input=false tfplanPrevent interleaving
- Run plan and apply close together under one concurrency lock per state.
- Pin the same Terraform version for both phases.
- Block other runs from mutating the state between plan and apply.
How to prevent it
- Serialize plan and apply for a given state.
- Pin one Terraform version across plan and apply.
- Use concurrency locks so state does not move mid-pipeline.