TerraformPilot

DevOps

Fix Terraform Error - Saved Plan Is Stale

How to fix 'saved plan is stale' and 'plan was created with a different version' errors when using terraform plan -out files.

LLuca Berton1 min read

The Error

#
Error: Saved plan is stale / the given plan file can no longer be applied

What Causes This

#

The saved plan file is outdated — someone else modified the infrastructure or state since the plan was generated. Terraform requires the real-world state to match exactly what existed when the plan was created.

How to Fix It

#

Solution 1: Generate a New Plan

#
# Simply re-plan and re-apply
terraform plan -out=tfplan
terraform apply tfplan

Solution 2: Use Plan Files in CI/CD Correctly

#
# GitLab CI — plan and apply in same pipeline
stages:
  - plan
  - apply
 
plan:
  stage: plan
  script:
    - terraform init
    - terraform plan -out=tfplan
  artifacts:
    paths:
      - tfplan
      - .terraform
      - .terraform.lock.hcl
 
apply:
  stage: apply
  script:
    - terraform apply tfplan
  dependencies:
    - plan
  when: manual
  only:
    - main

Solution 3: Prevent Concurrent Modifications

#
# Use state locking to prevent conflicts
# S3 backend with DynamoDB — enabled by default
 
# For local state, only one person should apply at a time

Best Practice: Short-Lived Plans

#
# Don't save plans for later — apply soon after planning
terraform plan -out=tfplan && terraform apply tfplan
 
# In CI/CD, plan and apply should be in the same pipeline run

Prevention Tips

#
  1. Pin provider versions — avoid surprise breaking changes
  2. Use CI/CD — catch errors before they hit production
  3. Test with terraform plan — always review before applying
  4. Keep Terraform updated — newer versions have better error messages
  5. Use terraform validate — catches syntax errors early

Hands-On Courses

#

Learn to avoid these errors with interactive, project-based courses:

#

Conclusion

#

This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

#Terraform#Troubleshooting#DevOps#Error Fix#Infrastructure as Code

Share this article