-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
231 lines (194 loc) · 5.09 KB
/
main.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
provider "aws" {
region = "us-east-1"
}
data "aws_vpc" "default" {
default = true
}
data "aws_subnet" "default" {
for_each = toset(["use1-az1", "use1-az2"])
availability_zone_id = each.key
default_for_az = true
}
###################################################
# Application Load Balancer
###################################################
module "alb" {
source = "../../modules/alb"
# source = "tedilabs/load-balancer/aws//modules/alb"
# version = "~> 1.0.0"
name = "tedilabs-alb-ip"
is_public = false
ip_address_type = "IPV4"
vpc_id = data.aws_vpc.default.id
network_mapping = {
for az, subnet in data.aws_subnet.default :
az => {
subnet = subnet.id
}
}
default_security_group = {
enabled = true
name = "tedilabs-alb-ip"
description = "Managed by Terraform."
listener_ingress_ipv4_cidrs = ["10.0.0.0/8", "172.31.0.0/16"]
}
security_groups = []
## Attributes
desync_mitigation_mode = "DEFENSIVE"
drop_invalid_header_fields = false
deletion_protection_enabled = false
http2_enabled = true
waf_fail_open_enabled = false
idle_timeout = 60
listeners = [
{
port = 80
protocol = "HTTP"
default_action_type = "REDIRECT_301"
default_action_parameters = {
protocol = "HTTPS"
port = 443
}
},
{
port = 8080
protocol = "HTTP"
default_action_type = "FIXED_RESPONSE"
default_action_parameters = {
content_type = "application/json"
status_code = 404
data = <<EOF
{"status":"fail","metadata":{"statusCode":"404","code":"UNKNOWN_ENDPOINT","description":"The requested endpoint does not exist."}}
EOF
}
rules = [
{
priority = 10
conditions = [
{
type = "HOST"
values = ["*.tedilabs.com", "abc.tedilabs.com"]
}
]
action_type = "FORWARD"
action_parameters = {
target_group = module.target_group_alpha.arn
}
},
{
priority = 20
conditions = [
{
type = "HOST"
values = ["my-service.dev.tedilabs.com"]
}
]
action_type = "WEIGHTED_FORWARD"
action_parameters = {
targets = [
{
target_group = module.target_group_alpha.arn
weight = 3
},
{
target_group = module.target_group_beta.arn
weight = 1
},
]
}
}
]
},
]
## Access Log
access_log = {
enabled = false
s3_bucket = {
name = "my-bucket"
key_prefix = "/tedilabs-alb-ip/"
}
}
tags = {
"project" = "terraform-aws-load-balancer-examples"
}
}
###################################################
# IP Target Group for Application Load Balancer
###################################################
module "target_group_alpha" {
source = "../../modules/alb-ip-target-group"
# source = "tedilabs/load-balancer/aws//modules/alb-ip-target-group"
# version = "~> 1.0.0"
name = "tedilabs-alb-ip-alpha-tg"
vpc_id = data.aws_vpc.default.id
ip_address_type = "IPV4"
port = 80
protocol = "HTTP"
protocol_version = "HTTP1"
## Attributes
deregistration_delay = 300
load_balancing_algorithm = "ROUND_ROBIN"
slow_start_duration = 0
stickiness_enabled = true
stickiness_type = "LB_COOKIE"
stickiness_duration = 86400
targets = [
{
ip_address = "10.123.123.234"
},
{
ip_address = "10.0.103.34"
port = 999
},
]
health_check = {
protocol = "HTTP"
port = 80
port_override = false
path = "/health"
interval = 10
timeout = 5
healthy_threshold = 5
unhealthy_threshold = 2
}
tags = {
"project" = "terraform-aws-load-balancer-examples"
}
}
module "target_group_beta" {
source = "../../modules/alb-ip-target-group"
# source = "tedilabs/load-balancer/aws//modules/alb-ip-target-group"
# version = "~> 1.0.0"
name = "tedilabs-alb-ip-beta-tg"
vpc_id = data.aws_vpc.default.id
ip_address_type = "IPV4"
port = 80
protocol = "HTTP"
protocol_version = "HTTP1"
## Attributes
deregistration_delay = 300
load_balancing_algorithm = "ROUND_ROBIN"
slow_start_duration = 0
stickiness_enabled = true
stickiness_type = "APP_COOKIE"
stickiness_duration = 86400
stickiness_cookie = "X-TEDILABS-SESSION"
targets = [
{
ip_address = "10.234.1.234"
},
]
health_check = {
protocol = "HTTP"
port = 80
port_override = false
path = "/health"
interval = 10
timeout = 5
healthy_threshold = 5
unhealthy_threshold = 2
}
tags = {
"project" = "terraform-aws-load-balancer-examples"
}
}