-
Notifications
You must be signed in to change notification settings - Fork 0
/
lb.tf
81 lines (69 loc) · 1.74 KB
/
lb.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
resource "aws_lb" "web_lb" {
name = "web-lb"
load_balancer_type = "application"
#subnets = data.aws_subnets.default.ids
subnets = aws_subnet.subnet.*.id
security_groups = [aws_security_group.web_lb_sg.id]
depends_on = [
aws_subnet.subnet
]
}
resource "aws_lb_listener" "web_lb_listener" {
load_balancer_arn = aws_lb.web_lb.arn
port = 80
protocol = "HTTP"
default_action {
type = "fixed-response"
fixed_response {
content_type = "text/plain"
message_body = "404: page not found"
status_code = 404
}
}
}
resource "aws_security_group" "web_lb_sg" {
name = "web-lb-sg"
vpc_id = aws_vpc.vpc.id
# Allow inbound http
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# Allow all outbound requests
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_lb_target_group" "tg" {
name = "web-tg"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.vpc.id
health_check {
path = "/"
protocol = "HTTP"
matcher = "200"
interval = 15
timeout = 3
healthy_threshold = 2
unhealthy_threshold = 2
}
}
resource "aws_lb_listener_rule" "asg" {
listener_arn = aws_lb_listener.web_lb_listener.arn
priority = 100
condition {
path_pattern {
values = ["*"]
}
}
action {
type = "forward"
target_group_arn = aws_lb_target_group.tg.arn
}
}