narliecholler
narliecholler

Reputation: 479

How can I fix: Terraform error refreshing state: state snapshot was created by Terraform v0.14.5, which is newer than current v0.13.0

I am trying to upgrade my terraform version from 0.12 to 0.13 but had previously init and planned with globally install terraform 0.14.5.

I'm struggling to understand how this effects the snapshot and/or I can remove this error, remote state hasn't changed so where is it getting this from? I have removed any .terraform in the directory.

Upvotes: 2

Views: 4056

Answers (1)

β.εηοιτ.βε
β.εηοιτ.βε

Reputation: 39149

Terraform is holding its state either in a remote backend or in a local one.

If you have no configuration that looks like this in your configuration files, minding that the backend type might differ based on the one used, so the name in "..." might vary:

terraform {
  backend "..." { 
  }
}

Then it would be safe to assume you have a local JSON state file named terraform.tfsate, and also, since your project existed before the upgrade, a file terraform.tfsate.backup.

If you peak into those files, you will see the version of terraform used to create the said state in the beginning of the file.

For example:

{
  "version": 4,
  "terraform_version": "0.14.5",
}

From there, and with all the caution in the world, ensuring you indeed didn't change anything in the remote state, you have some options:

  1. if your file terraform.tfsate.backup still have "terraform_version": "0.13.0", you could just make a rollback by removing the terraform.tfsate and renaming terraform.tfsate.backup to terraform.tfsate
  2. you can try to "hack" into the actual terraform.tfsate and change the version there by adapting the line "terraform_version": "0.14.5"
  3. As advised in the below link, you could create a state version using the API, so, overriding the state by manually specifying your expected version terraform_version

My advise still, would be to make a diff of terraform.tfsate against terraform.tfsate.backup to see what have possibly changed, or use a versioning tool if your terraform.tfsate is under version control.

Useful read: https://support.hashicorp.com/hc/en-us/articles/360001147287-Downgrading-Terraform-Version-in-the-State

Upvotes: 2

Related Questions