state snapshot was created by Terraform v0.12.29, which is newer than

Viewed 6727

I'm using Terraform with s3 as backend, every worked great before but just recently i got the following error message when running terraform plan or apply

Error: state snapshot was created by Terraform v0.14.8, which is newer than current v0.12.29; upgrade to Terraform v0.14.8 or greater to work with this state

The strange thing is I already forced the Terraform version:

terraform {
  required_version = ">= 0.12"
}

And when I pulled the latest state from s3,the version is still 0.12.29.

terraform state pull | grep version

"terraform_version": "0.12.29",
  ....

I really have no idea where the version 0.14.8 comes from.

2 Answers

Happened to me, my deployment (CICD) failed and left a lock in the TF state.

So I just went and manually removed the lock from my local

terraform init -backend-config="key=prod/app1.tfstate"

terraform force-unlock -force xxxxx-8df6-a7e8-46a8-xxxxxxxxxxxx

Then I try to redeploy from CI/CD and get that error, because my local was higher version than terraform running in the CI/CD.

In the end, I did this to restore to the previous state:

  1. S3: find the state file, restore the old version (versioning enabled in this bucket)

  2. Run this again: terraform init -backend-config="key=prod/app1.tfstate" -reconfigure

To get the response below with the previous digest value:


Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Error refreshing state: state data in S3 does not have the expected content.

This may be caused by unusually long delays in S3 processing a previous state
update.  Please wait for a minute or two and try again. If this problem
persists, and neither S3 nor DynamoDB are experiencing an outage, you may need
to manually verify the remote state and update the Digest value stored in the
DynamoDB table to the following value: ebf597a8a25619b959baaa34a7b9d905
  1. Update the dynamo item with the digest above

  2. Run deployment again

Are you the only developer working on terraform? Are you running terraform locally or also via some pipeline? There is a strong possibility that one of your team member upgraded their terraform binary to the v0.14.8 version and applied locally (without updating the remote state) and now you would need to upgrade to that version as well

Its not just the version of the terraform state that you are accessing/running plan against. Terraform cross-references a lot of terraform states internally. So just go inside the remote state bucket and try to find that one specific remote state with different tf version.

Related