-
Notifications
You must be signed in to change notification settings - Fork 0
/
alb.tf
118 lines (112 loc) · 2.79 KB
/
alb.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
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
module "alb" {
source = "terraform-aws-modules/alb/aws"
version = "8.6.0"
name = "alb-${var.app_env}"
load_balancer_type = "application"
vpc_id = aws_vpc.main.id
subnets = aws_subnet.public.*.id
security_groups = [aws_security_group.alb.id]
http_tcp_listeners = [
{
port = 80
protocol = "HTTP"
action_type = "redirect"
redirect = {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
},
]
https_listeners = [
{
port = 443
protocol = "HTTPS"
certificate_arn = module.acm.acm_certificate_arn
},
]
https_listener_rules = [
{
https_listener_index = 0
actions = [
{
type = "forward"
target_group_index = 0
},
]
conditions = [
{
host_headers = [var.app_domain]
},
]
},
{
https_listener_index = 0
actions = [
{
type = "forward"
target_group_index = 1
},
]
conditions = [
{
host_headers = ["api.${var.app_domain}"]
},
]
},
]
target_groups = [
{
backend_protocol = "HTTP"
backend_port = var.web_app_port
target_type = "instance"
health_check = {
enabled = true
interval = 30
path = "/index.html"
port = "traffic-port"
healthy_threshold = 3
unhealthy_threshold = 3
timeout = 6
protocol = "HTTP"
matcher = "200-399"
}
targets = {
for index, web_server in aws_instance.web_servers :
index => {
target_id = web_server.id
port = var.web_app_port
}
}
},
{
backend_protocol = "HTTP"
backend_port = var.api_app_port
target_type = "instance"
health_check = {
enabled = true
interval = 30
path = "/health"
port = "traffic-port"
healthy_threshold = 3
unhealthy_threshold = 3
timeout = 6
protocol = "HTTP"
matcher = "200-399"
}
targets = {
for index, web_server in aws_instance.web_servers :
index => {
target_id = web_server.id
port = var.api_app_port
}
}
},
]
tags = var.tags
lb_tags = var.tags
target_group_tags = var.tags
https_listener_rules_tags = var.tags
https_listeners_tags = var.tags
http_tcp_listeners_tags = var.tags
}