-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalb.tf
More file actions
120 lines (101 loc) · 2.81 KB
/
alb.tf
File metadata and controls
120 lines (101 loc) · 2.81 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
resource "aws_lb" "packy-v2-alb" {
name = "packy-v2-alb"
internal = false
load_balancer_type = "application"
security_groups = [ aws_security_group.packy-v2-alb-sg.id ]
subnets = [ aws_subnet.packy-v2-public-subnet-01.id, aws_subnet.packy-v2-public-subnet-02.id ]
enable_deletion_protection = false
}
resource "aws_lb_target_group" "packy-v2-web-dev-tg" {
name = "packy-v2-web-dev-tg"
port = 3000
protocol = "HTTP"
vpc_id = aws_vpc.packy-v2-vpc.id
health_check {
path = "/"
interval = 30
timeout = 5
healthy_threshold = 5
unhealthy_threshold = 2
}
}
resource "aws_lb_target_group" "packy-v2-web-prod-tg" {
name = "packy-v2-web-prod-tg"
port = 3001
protocol = "HTTP"
vpc_id = aws_vpc.packy-v2-vpc.id
health_check {
path = "/"
interval = 30
timeout = 5
healthy_threshold = 5
unhealthy_threshold = 2
}
}
resource "aws_lb_target_group_attachment" "packy-v2-web-dev-tg-attachment" {
target_group_arn = aws_lb_target_group.packy-v2-web-dev-tg.arn
target_id = aws_instance.packy-v2-web-ec2.id
port = 3000
}
resource "aws_lb_target_group_attachment" "packy-v2-web-prod-tg-attachment" {
target_group_arn = aws_lb_target_group.packy-v2-web-prod-tg.arn
target_id = aws_instance.packy-v2-web-ec2.id
port = 3001
}
resource "aws_lb_listener" "packy-v2-alb-http-listener" {
load_balancer_arn = aws_lb.packy-v2-alb.arn
port = 80
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
host = "#{host}"
path = "/#{path}"
port = "443"
protocol = "HTTPS"
query = "#{query}"
status_code = "HTTP_301"
}
}
}
resource "aws_lb_listener" "packy-v2-alb-https-listener" {
load_balancer_arn = aws_lb.packy-v2-alb.arn
port = 443
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = aws_acm_certificate.packy-v2-web-acm-wildcard.arn
default_action {
type = "fixed-response"
fixed_response {
content_type = "text/plain"
message_body = "Not Found"
status_code = "404"
}
}
}
resource "aws_lb_listener_rule" "packy-v2-lb-web-listener-rule-dev" {
listener_arn = aws_lb_listener.packy-v2-alb-https-listener.arn
priority = 1
condition {
host_header {
values = [ "dev.packyforyou.com" ]
}
}
action {
type = "forward"
target_group_arn = aws_lb_target_group.packy-v2-web-dev-tg.arn
}
}
resource "aws_lb_listener_rule" "packy-v2-lb-web-listener-rule-prod" {
listener_arn = aws_lb_listener.packy-v2-alb-https-listener.arn
priority = 2
condition {
host_header {
values = [ "packyforyou.com" ]
}
}
action {
type = "forward"
target_group_arn = aws_lb_target_group.packy-v2-web-prod-tg.arn
}
}