我收到以下错误:
│ A reference to "each.value" has been used in a context in which it
│ unavailable, such as when the configuration no longer contains the value in
│ its "for_each" expression. Remove this reference to each.value in your
│ configuration to work around this error.
我想使用 for_each 循环和 every.value 来缩短我的代码。我已将其添加到变量中:
variable "log_categories" {
type = list(string)
default = ["AZFWApplicationRule", "AZFWApplicationRuleAggregation", "AZFWDnsQuery", "AZFWFqdnResolveFailure", "AZFWIdpsSignature", "AZFWNatRule", "AZFWNatRuleAggregation", "AZFWNetworkRule", "AZFWNetworkRuleAggregation", "AZFWThreatIntel", "AzureFirewallApplicationRule", "AzureFirewallDnsProxy", "AzureFirewallNetworkRule", "AllMetrics"]
}
这就是我使用 for.each 循环的地方:
log {
for_each = toset(var.log_categories)
category = each.value
retention_policy {
days = 30
enabled = false
}
}
}
不知道哪里出了问题。我已经尝试使用each.key而不是each.value,但也不起作用
最佳答案
我必须创建一个动态 block 才能使其工作:
dynamic "log" {
for_each = toset(var.log_categories)
content {
category = log.value
retention_policy {
days = 30
enabled = false
}
}
}
}
关于terraform - 此处不能使用each.value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73154414/