我正在使用tfenv切换地形版本。最近我遇到了这个错误,我不知道该怎么解决。
有人能告诉我这里发生了什么吗,为什么不能检测到最低要求的版本?
错误:
tfenv install min-required && tfenv use min-required && terraform init -backend=false ./stage; terraform validate -var="api_key=xxxx" ./stage
Error: Could not determine required_version based on your terraform sources.
Make sure at least one of your *tf files includes a required version section like
terraform {
required_version = ">= 0.0.0"
}
see https://www.terraform.io/docs/configuration/terraform.html for details
tfenv-min-required failed
grep: brackets ([ ]) not balanced
No versions matching 'min-required' found in remote
Makefile:
DUTY_VAR=-var=api_key=xxxx test: tfenv install min-required && tfenv use min-required && terraform init -backend=false ./stage; terraform validate ${DUTY_VAR} ./stage
Terraform文件夹/文件结构:
|-terraform (directory)
|-modules ( directory)
| - main.tf
| - variables.tf
| - versions.tf
|
|-stage(root-module)(directory)
| - backend.tf
| - main.tf
| - .terraform-version
| - providers.tf
版本.tf
terraform {
required_version = "0.11.13"
}
后端.tf
terraform {
required_version = "0.11.13"
backend "s3" {
bucket = "nonprod"
key = "tfstate/terraform.tfstate"
dynamodb_table = "terraform-state-lock"
region = "us-east-1"
encrypt = true
role_arn = "arn:aws:iam::zzzzzzz:role/yyy"
}
}
这个答案有两个部分,如下所述,
第1部分
如错误中所述,请尝试在required_version
设置中指定地形版本,如下所示,
required_version = ">= 0.11.13"
请注意>=
第2部分
根据Terraform文档,模块应仅限制其允许的最低版本的Terraform和提供者,如>= 0.12.0
请参阅Terraform版本约束文档
因此,不要使用Terraform版本0.11.13
,而是尝试使用版本0.12.0