Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform load balancer with multiple listeners

Given this Terraform script for creating an AWS Elastic Load Balancer:

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
}

How would it be modified to create multiple listeners?

like image 683
UtpMahesh Avatar asked Dec 03 '16 02:12

UtpMahesh


People also ask

How many listeners can a load balancer have?

Application Load Balancers provide native support for HTTP/2 with HTTPS listeners. You can send up to 128 requests in parallel using one HTTP/2 connection.


1 Answers

You need to pass a list of maps to the listener.

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"
  }]

Alternatively,

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

where var.elb_listeners is a list of map as in the first example above.

like image 105
Anshu Prateek Avatar answered Oct 01 '22 14:10

Anshu Prateek