for_each循环string
resource "" ""{
for_each = toset(var.names)
name = each.value
}
variable "names" {
type = list(string)
default = []
}
使用条件控制for_each循环对象
resource "goole" "autoscaler"{
for_each = var.autoscaling_enabled ? toset({for autoscaling in var.autoscaling_rules:autoscaling.name=>autoscaling}): toset([])
key = "${each.key}"
target = each.value.target
}
variable "autoscaling_enabled" {
type = bool
default = false
}
variable "autoscaling_rules" {
type = list(object({
name = string
target =number
}))
default = []
}