Terraform: Terraform should provide a clear indication of which remote state is incompatible

Created on 10 Sep 2020  路  6Comments  路  Source: hashicorp/terraform

Terraform Configuration Files


Using this code with Terraform 0.12.29:

terraform {
  backend "s3" {
    bucket         = "2u-terraform"
    region         = "us-east-1"
    key            = "tf0.12-test"
    dynamodb_table = "terraform-locks"
  }

  required_version = "= 0.12.29"
}

resource "random_string" "random" {
  length           = 16
  special          = true
  override_special = "/@拢$"
}

output "random_tf12_output" {
  value = random_string.random.result
}

data "terraform_remote_state" "tf13_source" {
  backend = "s3"

  config = {
    bucket = "2u-terraform"
    key    = "tf0.13-test"
    region = "us-east-1"
  }
}

output "output_from_remote_tf13_state" {
  value = data.terraform_remote_state.tf13_source.outputs.random_tf13_output
}

And running terraform apply:

$ terraform apply
random_string.random: Refreshing state... [id=jl2dJoQ89oV3wd@L]
data.terraform_remote_state.tf13_source: Refreshing state...

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

Using this code with Terraform 0.13.2:

terraform {
  backend "s3" {
    bucket         = "2u-terraform"
    region         = "us-east-1"
    key            = "tf0.13-test"
    dynamodb_table = "terraform-locks"
  }

  required_version = "= 0.13.2"

}

resource "random_string" "random" {
  length           = 16
  special          = true
  override_special = "/@拢$"
}

output "random_tf13_output" {
  value = random_string.random.result
}

data "terraform_remote_state" "tf12_source" {
  backend = "s3"

  config = {
    bucket = "2u-terraform"
    key    = "tf0.12-test"
    region = "us-east-1"
  }
}

output "output_from_remote_tf12_state" {
  value = data.terraform_remote_state.tf12_source.outputs.random_tf12_output
}

And running terraform apply:

$ terraform apply
data.terraform_remote_state.tf12_source: Refreshing state...
random_string.random: Refreshing state... [id=fLrTR7y6w3PzwC锟絜]

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

output_from_remote_tf12_state = jl2dJoQ89oV3wd@L
random_tf13_output = fLrTR7y6w3PzwC锟絜

Expected Behavior


Terraform 0.12 should be able to read outputs from 0.13 remote state. We're using remote states a lot with Terraform code on different versions, and it's impossible to upgrade everything to the same version at the same time.

Actual Behavior


Terraform threw the error below, which is confusing, it makes you think the problem is with your current state/code, and it doesn't say which remote state caused the error (helpful when using many remote states):

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

Steps to Reproduce

Using the code above for versions 0.12 and 0.13, run terraform apply using the corresponding Terraform version.

References

Also mentioned here: https://github.com/hashicorp/terraform/issues/25487#issuecomment-685864174

enhancement

Most helpful comment

We have now released Terraform versions 0.12.30 and 0.13.6, both of which allow reading remote state from all versions of Terraform at least through 1.0. That is, users of Terraform 0.12.30 and 0.13.6 will be able to access remote state written by other versions of Terraform including 0.11, 0.12, 0.13, and 0.14.

For more details, see the full changelogs:

https://github.com/hashicorp/terraform/blob/v0.12.30/CHANGELOG.md
https://github.com/hashicorp/terraform/blob/v0.13.6/CHANGELOG.md

All 6 comments

Just saw @apparentlymart's reply to https://github.com/hashicorp/terraform/issues/25412, bummer... Can the error be more specific at least? It's confusing right now, it would be helpful to know which remote state is causing the error.

@atrepca That's a helpful suggestion - would it be ok with you if I (or you) re-title this issue in that vein and change it from a bug to an enhancement request?

Sounds good @pkolyvas, please edit as needed, I can't change from bug to enhancement once submitted.

@atrepca @pkolyvas I think the original title and requirement is much better, just indicating incompatible remote state won't actually solve the problem @atrepca mentioned.

Terraform 0.12 should be able to read outputs from 0.13 remote state. We're using remote states a lot with Terraform code on different versions, and it's impossible to upgrade everything to the same version at the same time.

Hi @dogzzdogzz, I see you commented on https://github.com/hashicorp/terraform/issues/25412 too; @apparentlymart mentions there this is expected, that's why the change in scope here.

We have now released Terraform versions 0.12.30 and 0.13.6, both of which allow reading remote state from all versions of Terraform at least through 1.0. That is, users of Terraform 0.12.30 and 0.13.6 will be able to access remote state written by other versions of Terraform including 0.11, 0.12, 0.13, and 0.14.

For more details, see the full changelogs:

https://github.com/hashicorp/terraform/blob/v0.12.30/CHANGELOG.md
https://github.com/hashicorp/terraform/blob/v0.13.6/CHANGELOG.md

Was this page helpful?
0 / 5 - 0 ratings