Skip to content

Instantly share code, notes, and snippets.

@afcastano
Created August 19, 2019 11:05
Show Gist options
  • Save afcastano/ce27be974610214aa6c58501828ee099 to your computer and use it in GitHub Desktop.
Save afcastano/ce27be974610214aa6c58501828ee099 to your computer and use it in GitHub Desktop.
AWS Load Balancer
resource "aws_alb" "alb" {
subnets = ["${aws_subnet.pub_subnet_1.id}", "${aws_subnet.pub_subnet_2.id}"]
internal = false
security_groups = ["${aws_security_group.alb.id}"]
depends_on = ["aws_internet_gateway.app_igw", "aws_vpc_dhcp_options_association.dns_resolver"]
}
resource "aws_alb_target_group" "targ" {
port = 8080
protocol = "HTTP"
vpc_id = "${aws_vpc.app_vpc.id}"
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 5
path = "/"
interval = 30
port = 80
matcher = "200-399"
}
stickiness {
type = "lb_cookie"
enabled = true
}
}
resource "aws_alb_target_group_attachment" "attach_web" {
target_group_arn = "${aws_alb_target_group.targ.arn}"
target_id = "${element(aws_instance.wp.*.id, count.index)}"
port = 80
count = 2
}
resource "aws_alb_listener" "list" {
"default_action" {
target_group_arn = "${aws_alb_target_group.targ.arn}"
type = "forward"
}
load_balancer_arn = "${aws_alb.alb.arn}"
port = 80
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment