Created
August 19, 2019 11:05
-
-
Save afcastano/ce27be974610214aa6c58501828ee099 to your computer and use it in GitHub Desktop.
AWS Load Balancer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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