-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadbalancers.tf
34 lines (30 loc) · 901 Bytes
/
loadbalancers.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
resource "aws_lb_target_group" "FastAPI" {
name = "FastAPI"
target_type = "instance"
vpc_id = aws_vpc.Main.id
port = 8080
protocol = "HTTP"
}
resource "aws_lb_target_group_attachment" "FastAPI" {
for_each = {
for k, v in aws_instance.FastAPI : k => v
}
target_group_arn = aws_lb_target_group.FastAPI.arn
target_id = each.value.id
}
resource "aws_lb" "LoadBalancer" {
name = "FastAPI-LoadBalancer"
load_balancer_type = "application"
internal = false
security_groups = [aws_security_group.Load-Balancer.id]
subnets = aws_subnet.Public[*].id
}
resource "aws_lb_listener" "LoadBalancer" {
load_balancer_arn = aws_lb.LoadBalancer.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.FastAPI.arn
}
}