網頁

2021/9/3

Terraform Error refreshing state: state snapshot was created by Terraform v0.x.x, which is newer then current v0.y.y

執行Terraform terraform init命令時出現Error refreshing state: state snapshot was created by Terraform v0.x.x, which is newer then current v0.y.y錯誤。


問題發生原因是remote state的Terraform版本與專案的Terraform配置需求版本不一致。


專案的Terrafrom state是使用存在AWS S3remote stateterraform.tfstate,裡面設定的Terraform版本terraform_versionv.0.x.x如下。

s3://mybucket/demo/dev/terraform.tfstate

{
  "version": 3,
  "terraform_version": "0.x.x",
  "serial": 123,
  "lineage": "9876543a-98ab-123a-ff99-ff99e7aaff99",
  "resources": [...]
}

而專案Terraform的配置檔demo.tfterraformrequired_version為較舊的v0.y.y版本。

demo.tf

terraform {
  required_version = "v0.y.y"
  
  backend "s3" {
    bucket = "mybucket"
    key    = "demo/dev/terraform.tfstate"
    region = "us-east-1"
  }
}

只要把required_version設定為和remote state相同為v0.x.x即可解決。


沒有留言:

張貼留言