Today I’m going to show you a quick solution on how to resolve just another TF error:
╷
│ 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.
╵
Prerequisites
- Terraform
Solution
As the error description suggests, the state was modified after the plan was created. The solution is quite simple. You need to recreate the plan. Let’s say the plan was saved under tfplan
. Run the following commands:
rm tfplan
terraform plan -out=tfplan
terraform apply tfplan
Now, if you want to know the changes and what caused the modified state, there isn’t a one-command way to do so. What you could do is:
- Save the current (“old”) state in a plain text file –
terraform show -no-color tfplan > tfplan.old.txt
- Export a new terraform plan in a plain text –
terraform plan -no-color > tfplan.new.txt
- Find the difference on what was changed your favorite IDE tool or from the CLI –
diff tfplan.old.txt tfplan.new.txt
Conclusion
If you have any related unresolved issues, feel free to share them in the comment section below. On a side note, follow our official channel on Telegram.