-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_balancer.tf
executable file
·37 lines (32 loc) · 1.16 KB
/
load_balancer.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
resource "aws_lb" "main_lb" {
name = "main-loadbalancer"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.load_balancer_security_group.id]
subnets = [aws_subnet.Public_webserver_zone_a.id, aws_subnet.Public_webserver_zone_b.id]
}
resource "aws_alb_target_group" "alb_front_http_webservers" {
name = "alb-front-http"
vpc_id = aws_vpc.VPC.id
port = "80"
protocol = "HTTP"
}
resource "aws_alb_target_group_attachment" "alb_webserver_a_http" {
target_group_arn = aws_alb_target_group.alb_front_http_webservers.arn
target_id = aws_instance.webserver_a.id
port = 80
}
resource "aws_alb_target_group_attachment" "alb_webserver_b_http" {
target_group_arn = aws_alb_target_group.alb_front_http_webservers.arn
target_id = aws_instance.webserver_b.id
port = 80
}
resource "aws_lb_listener" "front_end" {
load_balancer_arn = aws_lb.main_lb.arn
port = "80"
protocol = "HTTP"
default_action {
target_group_arn = aws_alb_target_group.alb_front_http_webservers.arn
type = "forward"
}
}