執行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 S3的remote state檔terraform.tfstate
,裡面設定的Terraform版本terraform_version
為v.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.tf
中terraform
的required_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
即可解決。
沒有留言:
張貼留言