在 terraform 中,我有一张地图service_map:
variable "service_map" {
type = map
description = "Map of some services and their ports."
default = {
"dns" = "53"
"web" = "443"
"ssh" = "22"
"proxy" = ""
}
}
Run Code Online (Sandbox Code Playgroud)
要在 AWS 上创建 LB 侦听器,我想调用资源aws_lb_listener,循环遍历地图service_map,跳过所有没有值的项目(在本例中,仅跳过proxy):
resource "aws_lb_listener" "listeners" {
for_each = var.service_map
load_balancer_arn = aws_lb.all_lbs[each.key].arn
port = each.value
protocol = each.key != "dns" ? "TCP" : "TCP_UDP"
default_action {
type = "forward"
target_group_arn = …Run Code Online (Sandbox Code Playgroud)