地形alb规则条件插值

时间:2019-11-28 04:12:27

标签: terraform interpolation devops terraform-provider-aws aws-elb

如何用条件中带有“值”的变量替换列表中的元素。

resource "aws_alb_listener_rule" "static" {
  count         = length(values(var.services_map))
  listener_arn  = aws_alb_listener.supply_alb.arn
  priority      = 1 + count.index

  action {
    type = "forward"
    target_group_arn = element(keys(var.services_map), count.index)
  }

  condition {
    field = "host-header"
    values = ["${(element(values(var.services_map), count.index)}"]
  }

  lifecycle {
    ignore_changes = [priority]
  }
}

===

variable services_map {
  default = {
    backend-writing-tg =  ["/api/2.0/cart"]

    backend-scaling-tg = ["/api/1.0/travel/test/test1", "/api/1.0/travel/test3", "/api/1.0/travel/test4"]
  }
}

我希望terraform根据variables.tf中的services_map“键”和“值”创建多个alb侦听器规则。

0 个答案:

没有答案