-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_balancer.tf
More file actions
32 lines (27 loc) · 813 Bytes
/
Copy pathload_balancer.tf
File metadata and controls
32 lines (27 loc) · 813 Bytes
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
# =========== Creating a load balancer
resource "aws_alb" "lb" {
name = "nginx-load-balancer"
subnets = aws_subnet.public.*.id
security_groups = [aws_security_group.lb.id]
}
# =========== Createing a target group
resource "aws_alb_target_group" "target" {
vpc_id = aws_vpc.main.id
name = "nginx-target-group"
port = var.app_type.port
protocol = "HTTP"
target_type = "ip"
health_check {
path = "/"
matcher = "200"
}
}
# =========== Redirect incoming traffic to target from lb
resource "aws_alb_listener" "listen" {
load_balancer_arn = aws_alb.lb.arn
port = var.app_type.port
default_action {
type = "forward"
target_group_arn = aws_alb_target_group.target.arn
}
}