Terraform 0.13 刚刚发布(https://www.hashicorp.com/blog/annoucing-hashicorp-terraform-0-13/),它改变了与 3rd 方提供商合作的方式(https://www.terraform.io/ upgrade-guides/0-13.html#explicit-provider-source-locations)。
我在运行时遇到错误terraform init
:
$ terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/ibm...
Error: Failed to install provider
Error while installing hashicorp/ibm: provider registry registry.terraform.io
does not have a provider named registry.terraform.io/hashicorp/ibm
Run Code Online (Sandbox Code Playgroud)
这曾经适用于 Terraform 0.12.29 和 IBM 供应商 1.10.0。
我知道 CI/CD 变量可以在 HCL 中使用,因为在环境中使用 TF_VAR_ 前缀声明它们将使我能够将它们作为输入变量查找,然后在我所在的 .tf 文件中使用它们。需要他们。
\n我做了:
\nTF_VAR_ibm_api_key
,然后屏蔽它。main.tf
main.tf
variables.tf
,结果相同这是我的main.tf
文件:
variable ibm_api_key {\n}\n\nterraform {\n required_version = ">= 0.13"\nrequired_providers {\n ibm = {\n source = "IBM-Cloud/ibm"\n }\n }\n}\n\nprovider "ibm" {\n ibmcloud_api_key = var.ibm_api_key\n}\n
Run Code Online (Sandbox Code Playgroud)\n预期行为:变量从 CI/CD 传递并添加到 HCL 代码中。
\n当前行为:在 \xc2\xb4plan\xc2\xb4 期间,作业失败并出现错误代码 1
\n$ terraform plan\nvar.ibm_api_key\n …
Run Code Online (Sandbox Code Playgroud) 地形版本:“1.2.9”
\nlist(object({}))
当具有类型并标记为的输入变量sensitive = true
传递给dynamic
块时,Terraform 失败并出现无效值错误for_each
。\n当输入变量标记为不敏感时,不会出现该错误。
输入变量如下所示:
\nvariable "sample_variable" {\n type = list(object({\n name = string\n description = optional(string)\n secure = optional(bool)\n type = string\n use_default = optional(bool)\n value = string\n }))\n sensitive = true\n description = "A list of objects with sensitive values."\n default = []\n}\n
Run Code Online (Sandbox Code Playgroud)\ndynamic
并在资源块中消耗,for_each
如下所示:
resource "ibm_cloud_sample_resource" "my_resource" {\n name = var.name\n description = var.description\n template_env_settings = local.env_values\n tags = var.tags\n dynamic "template_inputs" …
Run Code Online (Sandbox Code Playgroud)