-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadbalancer.tf
46 lines (40 loc) · 1.06 KB
/
loadbalancer.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
38
39
40
41
42
43
44
45
46
# Application Load Balancer
resource "aws_lb" "wordpress_alb" {
name = "wordpress-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.ALB_SG.id]
subnets = aws_subnet.public-subnets[*].id
tags = {
Name = "wordpress-alb"
}
}
# Target Group for ECS Service
resource "aws_lb_target_group" "wordpress_tg" {
name = "wordpress-tg"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.wordpress.id
target_type = "ip" # Fargate requires "ip"
health_check {
path = "/"
interval = 30
timeout = 5
healthy_threshold = 3
unhealthy_threshold = 3
matcher = "200"
}
tags = {
Name = "wordpress-tg"
}
}
# Listener for ALB
resource "aws_lb_listener" "http_listener" {
load_balancer_arn = aws_lb.wordpress_alb.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.wordpress_tg.arn
}
}