我有一些带有一个字段的对象类型变量,我需要创建几个块作为字符串列表(var.kubernetes_worker_group_spec.zones):
kubernetes_worker_group_spec = ({
node_count = 1
platform = "standard-v2"
cores = 8
core_fraction = 100
memory = 16
gpus = 0
disk_type = "network-ssd"
disk_size = 100
nat = false
preemptible = false
subnet_ids = ["someid","someid2","someid3"]
zones = ["ru-central1-a", "ru-central1-b", "ru-central1-c"]
labels = {env = "SETMEUP"}
taints = ["env=SETMEUP:NoSchedule"]
unsafe_sysctls = ["net.core.somaxconn"]
serial_is_enabled = 0
})
现在某些资源需要声明几个带有区域名称的“位置”块:
resource "yandex_kubernetes_node_group" "some_node_group {
blahblahblah
allocation_policy {
location {
zone = "ru-central1-a"
}
}
blahblahblah
}
所以我想要location
由列表 subnet_ids 形成的几个块,但它看起来只for_each
用于动态块创建,但不可能将它与列表一起使用。
我认为它应该是这样的:
allocation_policy {
dynamic location {
for l in var.kubernetes_worker_group_spec.zones
content {
zone = var.kubernetes_worker_group_spec.zones[l]
}
}
}
但由于表达方式有点不同,这个当然不起作用......也许有一些解决方法......任何帮助都值得赞赏!=)