How to fix Error: Saved plan is stale in Terraform
A saved Terraform plan can no longer be applied because the state was modified after the plan was created. Regenerating the plan resolves this issue.
Quick fix
Fixes Error: Saved plan is stale
rm tfplan- Delete the stale plan file
- Regenerate the plan
- Apply the new plan
- For CI/CD: Use -reconfigure if needed
rm tfplanError: Saved plan is stale
What this error means
Terraform plans are bound to a specific state snapshot. When you run terraform plan, Terraform captures the current state and creates a plan based on what changes are needed. If the state is modified by another operation before you apply the plan, Terraform detects the mismatch and rejects the application. This safety mechanism prevents applying plans that may be based on outdated infrastructure state, which could cause unexpected resource modifications or conflicts.
Typical symptoms
- terraform apply fails with 'Saved plan is stale' error message
- Error occurs even when no changes have been made to configuration
- Plan applies successfully in one CI/CD stage but fails in subsequent stages
- Error happens immediately after state is modified by concurrent operations
- terraform show command fails with stale plan error
Common causes
- State was modified by another terraform apply operation after the plan was created
- Concurrent CI/CD pipelines or team members running terraform apply simultaneously
- Data sources that generate values on every apply (random, timestamps) incrementing state serial
- State backend's 'Last Modified' timestamp changed even though content didn't change
- State blob was modified by infrastructure drift detection or manual updates
- Multiple environments or workspaces sharing the same state or backend credentials
How to fix "Error: Saved plan is stale"
Remove the saved plan file from your working directory. This is the quickest solution for local development:
rm tfplanOr if your plan file has a different name:
rm [plan-filename]This prevents Terraform from attempting to use outdated plan data.
Create a fresh plan based on the current state:
terraform plan -out=tfplanThis reads the latest state and compares it against your current configuration. Any changes since the previous plan will be captured in the new plan file.
Apply the newly generated plan:
terraform apply tfplanSince this plan was just created, it matches the current state and will apply successfully.
If you're in a CI/CD pipeline and the state has changed between stages, use -reconfigure to force Terraform to detect the current state:
terraform init
terraform plan -out=tfplan
terraform apply tfplanAlways run terraform init in CI/CD pipelines to ensure plugin cache and backend configuration are properly set up before planning.
To understand what caused the state to change, compare the old and new plans:
terraform show -no-color tfplan.old > tfplan.old.txt
terraform plan -no-color > tfplan.new.txt
diff tfplan.old.txt tfplan.new.txtThis shows you what infrastructure differences Terraform detected between plan generations.
Advanced notes
Data Source Drift: Some data sources generate new values on every apply (like random providers or timestamp functions). These cause the state serial to increment even though no resources changed. To debug this, check your terraform logs with TF_LOG=DEBUG.
CI/CD Pipeline Considerations: In multi-stage pipelines, ensure only one stage can run terraform apply at a time. Use state locking with backends like S3+DynamoDB, Azure Blob Storage, or Terraform Cloud to prevent concurrent modifications.
State Locking: Verify your backend supports state locking:
terraform {
backend "s3" {
dynamodb_table = "terraform-locks"
}
}Azure-Specific Issue: On Azure, the error may trigger based on blob 'Last Modified' timestamp changes rather than actual content changes. Consider using Terraform Cloud or Enterprise for more reliable state locking.
Terragrunt Users: If using Terragrunt across multiple environments, ensure each environment has isolated state. A common cause is sharing state between stages when using artifacts.
Frequently asked questions
- What does "Error: Saved plan is stale" mean?
- Terraform plans are bound to a specific state snapshot. When you run terraform plan, Terraform captures the current state and creates a plan based on what changes are needed. If the state is modified by another operation before you apply the plan, Terraform detects the mismatch and rejects the application.
- How do I fix "Error: Saved plan is stale"?
- A saved Terraform plan can no longer be applied because the state was modified after the plan was created. Regenerating the plan resolves this issue.
- What causes "Error: Saved plan is stale"?
- State was modified by another terraform apply operation after the plan was created Concurrent CI/CD pipelines or team members running terraform apply simultaneously Data sources that generate values on every apply (random, timestamps) incrementing state serial
- Is the "Error: Saved plan is stale" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.