小编One*_*neK的帖子

循环遍历地图并跳过空项目

我想要的是

在 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)

terraform terraform-provider-aws

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

terraform ×1

terraform-provider-aws ×1