具有多个lisstners的terraform负载平衡器

时间:2016-12-03 02:19:36

标签: amazon-web-services terraform

我将在此粘贴我的terraform脚本以获取aws弹性负载均衡器

    resource "aws_elb" "elb" {
  name = "${var.elb_name}"
  subnets = ["${var.subnet_ids}"]
  internal = "${var.elb_is_internal}"
  security_groups = ["${var.elb_security_group}"]

  listener {
    instance_port = "${var.backend_port}"
    instance_protocol = "${var.backend_protocol}"
    lb_port = 80
    lb_protocol = "http"
  }

  health_check {
    healthy_threshold = 2
    unhealthy_threshold = 2
    timeout = 3
    target = "${var.health_check_target}"
    interval = 30
  }

  cross_zone_load_balancing = true
}

你们可以帮助我使用terraform变量创建多个监听器吗?

1 个答案:

答案 0 :(得分:4)

您需要将地图列表传递给侦听器。

listener = [{
    instance_port = "${var.backend_port}"
    instance_protocol = "${var.backend_protocol}"
    lb_port = 80
    lb_protocol = "http"
  },{
    instance_port = "${var.backend2_port}"
    instance_protocol = "${var.backend2_protocol}"
    lb_port = 8080
    lb_protocol = "http"
  }]

可替换地,

listener = ["${var.elb_listeners}"]

其中var.elb_listeners是上面第一个示例中的地图列表。