resource "aws_elb" "elb" {
  depends_on = ["aws_subnet.primary", "aws_subnet.secondary", "aws_nat_gateway.gw"]
  name               = "ELB"
  security_groups = ["${aws_security_group.sg-elb.id}"]

  listener {
    instance_port     = 80
    instance_protocol = "http"
    lb_port           = 80
    lb_protocol       = "http"
  }

  health_check {
    healthy_threshold   = 2
    unhealthy_threshold = 10
    timeout             = 30
    target              = "HTTP:80/"
    interval            = 60
  }

  subnets = ["${aws_subnet.primary.id}", "${aws_subnet.secondary.id}"]
  cross_zone_load_balancing   = true
  idle_timeout                = 400
  connection_draining         = true
  connection_draining_timeout = 400

  tags {
    Name = "TestELB"
  }
}
