嵌套块内的 Terraform 动态块不传递值
Terraform dynamic block inside a nested block not passing in values
我想使用 google_os_config_guest_policies 资源,但无法将值传递给 package_repositories
.
的嵌套代码块
子模块main.tf
package_repositories {
dynamic "apt" {
for_each = var.apt
content {
archive_type = lookup(apt.value, "archive_type", "abc")
uri = lookup(apt.value, "uri", "abc")
distribution = lookup(apt.value, "distribution", null)
components = lookup(apt.value, "components", null)
gpg_key = lookup(apt.value, "gpg_key", null)
}
}
}
Variables.tf
variable "apt" {
description = "Variable used for the APT block supported in the package_repositories variable. Pass in variables for apt_archive_type, apt_components, apt_distribution, apt_uri, apt_gpg_key."
type = any
default = []
}
terraform.tfvars
apt = [
{
archive_type = "DEB"
uri = "https://packages.cloud.google.com/apt"
distribution = "cloud-sdk-stretch"
components = ["main"]
}
]
每当我尝试从我的 tfvars 传递值时,在我的 terraform plan
步骤中,我只会得到一个空白的 package_repositories
映射。
+ package_repositories { }
我已尝试删除动态块并静态定义 package_repositories
的值,这没有任何问题。
package_repositories {
apt {
archive_type = "DEB"
uri = "https://packages.cloud.google.com/apt"
distribution = "cloud-sdk-stretch"
components = ["main"]
}
}
如果我尝试重新编写代码以使用动态 apt
块,它会尝试传入 null
值。语法有问题还是由于动态块不起作用的 beta 资源?
我试过了运行,我得到了想要的输出
+ package_repositories {
+ apt {
+ archive_type = "DEB"
+ components = [
+ "main",
]
+ distribution = "cloud-sdk-stretch"
+ uri = "https://packages.cloud.google.com/apt"
}
}
请确认您使用的是 terraform.tfvars
还是任何其他 tfvars 文件。如果是其他文件,您是否使用 -var-file 传递给您的 terraform 计划?
我想使用 google_os_config_guest_policies 资源,但无法将值传递给 package_repositories
.
子模块main.tf
package_repositories {
dynamic "apt" {
for_each = var.apt
content {
archive_type = lookup(apt.value, "archive_type", "abc")
uri = lookup(apt.value, "uri", "abc")
distribution = lookup(apt.value, "distribution", null)
components = lookup(apt.value, "components", null)
gpg_key = lookup(apt.value, "gpg_key", null)
}
}
}
Variables.tf
variable "apt" {
description = "Variable used for the APT block supported in the package_repositories variable. Pass in variables for apt_archive_type, apt_components, apt_distribution, apt_uri, apt_gpg_key."
type = any
default = []
}
terraform.tfvars
apt = [
{
archive_type = "DEB"
uri = "https://packages.cloud.google.com/apt"
distribution = "cloud-sdk-stretch"
components = ["main"]
}
]
每当我尝试从我的 tfvars 传递值时,在我的 terraform plan
步骤中,我只会得到一个空白的 package_repositories
映射。
+ package_repositories { }
我已尝试删除动态块并静态定义 package_repositories
的值,这没有任何问题。
package_repositories {
apt {
archive_type = "DEB"
uri = "https://packages.cloud.google.com/apt"
distribution = "cloud-sdk-stretch"
components = ["main"]
}
}
如果我尝试重新编写代码以使用动态 apt
块,它会尝试传入 null
值。语法有问题还是由于动态块不起作用的 beta 资源?
我试过了运行,我得到了想要的输出
+ package_repositories {
+ apt {
+ archive_type = "DEB"
+ components = [
+ "main",
]
+ distribution = "cloud-sdk-stretch"
+ uri = "https://packages.cloud.google.com/apt"
}
}
请确认您使用的是 terraform.tfvars
还是任何其他 tfvars 文件。如果是其他文件,您是否使用 -var-file 传递给您的 terraform 计划?