Skip to content

Commit 0c900d3

Browse files
authored
Completely deprecate old NLB from the metaflow-metadata-service module (#9)
This PR completely the deprecation of NLB and its migration to ALB towards DAT-106. The `moved` blocks will be removed with a later PR after a subsequent apply. Test plan --- Check that terraform plan reports destroy of old NLB but no other changes.
1 parent c9e9b23 commit 0c900d3

File tree

6 files changed

+75
-124
lines changed

6 files changed

+75
-124
lines changed

modules/metadata-service/api-gateway.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ resource "aws_api_gateway_resource" "db" {
5151
}
5252

5353
locals {
54-
alb_arn = var.setup_alb && var.point_api_gateway_to_alb ? aws_lb.apigw_nlb[0].arn : aws_lb.this.arn
55-
alb_dns_name = var.setup_alb && var.point_api_gateway_to_alb ? aws_lb.apigw_nlb[0].dns_name : aws_lb.this.dns_name
54+
alb_arn = aws_lb.apigw_nlb.arn
55+
alb_dns_name = aws_lb.apigw_nlb.dns_name
5656
}
5757

5858
resource "aws_api_gateway_vpc_link" "this" {

modules/metadata-service/ec2.tf

Lines changed: 68 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
moved {
2+
from = aws_lb.alb[0]
3+
to = aws_lb.alb
4+
}
5+
6+
moved {
7+
from = aws_lb_target_group.alb_main[0]
8+
to = aws_lb_target_group.alb_main
9+
}
10+
11+
moved {
12+
from = aws_lb_target_group.alb_db_migrate[0]
13+
to = aws_lb_target_group.alb_db_migrate
14+
}
15+
16+
moved {
17+
from = aws_lb_listener.alb_main[0]
18+
to = aws_lb_listener.alb_main
19+
}
20+
21+
moved {
22+
from = aws_lb_listener.alb_db_migrate[0]
23+
to = aws_lb_listener.alb_db_migrate
24+
}
25+
26+
moved {
27+
from = aws_lb.apigw_nlb[0]
28+
to = aws_lb.apigw_nlb
29+
}
30+
31+
moved {
32+
from = aws_lb_target_group.apigw_metadata[0]
33+
to = aws_lb_target_group.apigw_metadata
34+
}
35+
36+
moved {
37+
from = aws_lb_target_group.apigw_db_migrate[0]
38+
to = aws_lb_target_group.apigw_db_migrate
39+
}
40+
41+
moved {
42+
from = aws_lb_listener.apigw_metadata[0]
43+
to = aws_lb_listener.apigw_metadata
44+
}
45+
46+
moved {
47+
from = aws_lb_listener.apigw_db_migrate[0]
48+
to = aws_lb_listener.apigw_db_migrate
49+
}
50+
51+
moved {
52+
from = aws_security_group.metadata_alb_security_group[0]
53+
to = aws_security_group.metadata_alb_security_group
54+
}
55+
156
resource "aws_security_group" "metadata_service_security_group" {
257
name = local.metadata_service_security_group_name
358
description = "Security Group for Fargate which runs the Metadata Service."
@@ -45,8 +100,6 @@ resource "aws_security_group" "metadata_service_security_group" {
45100
}
46101

47102
resource "aws_security_group" "metadata_alb_security_group" {
48-
count = var.setup_alb ? 1 : 0
49-
50103
name = local.metadata_alb_security_group_name
51104
description = "Security Group for ALB which fronts the Metadata Service."
52105
vpc_id = var.metaflow_vpc_id
@@ -102,86 +155,18 @@ resource "aws_security_group_rule" "rds_sg_ingress" {
102155
security_group_id = var.database_sg_id
103156
}
104157

105-
resource "aws_lb" "this" {
106-
name = "${var.resource_prefix}nlb${var.resource_suffix}"
107-
internal = true
108-
load_balancer_type = "network"
109-
subnets = [var.subnet1_id, var.subnet2_id]
110-
111-
tags = var.standard_tags
112-
}
113-
114-
resource "aws_lb_target_group" "this" {
115-
name = "${var.resource_prefix}mdtg${var.resource_suffix}"
116-
port = 8080
117-
protocol = "TCP"
118-
target_type = "ip"
119-
vpc_id = var.metaflow_vpc_id
120-
121-
health_check {
122-
protocol = "TCP"
123-
interval = 10
124-
healthy_threshold = 2
125-
unhealthy_threshold = 2
126-
}
127-
128-
tags = var.standard_tags
129-
}
130-
131-
resource "aws_lb_target_group" "db_migrate" {
132-
name = "${var.resource_prefix}dbtg${var.resource_suffix}"
133-
port = 8082
134-
protocol = "TCP"
135-
target_type = "ip"
136-
vpc_id = var.metaflow_vpc_id
137-
138-
health_check {
139-
protocol = "TCP"
140-
port = 8080
141-
interval = 10
142-
healthy_threshold = 2
143-
unhealthy_threshold = 2
144-
}
145-
146-
tags = var.standard_tags
147-
}
148-
149-
resource "aws_lb_listener" "this" {
150-
load_balancer_arn = aws_lb.this.arn
151-
port = "80"
152-
protocol = "TCP"
153-
154-
default_action {
155-
type = "forward"
156-
target_group_arn = aws_lb_target_group.this.id
157-
}
158-
}
159-
160-
resource "aws_lb_listener" "db_migrate" {
161-
load_balancer_arn = aws_lb.this.arn
162-
port = "8082"
163-
protocol = "TCP"
164-
165-
default_action {
166-
type = "forward"
167-
target_group_arn = aws_lb_target_group.db_migrate.id
168-
}
169-
}
170-
171158
resource "aws_lb" "alb" {
172-
count = var.setup_alb ? 1 : 0
173159
name = "${var.resource_prefix}metadata-alb${var.resource_suffix}"
174160
internal = true
175161
load_balancer_type = "application"
176162
idle_timeout = 180 # 3 minutes
177163
subnets = [var.subnet1_id, var.subnet2_id]
178-
security_groups = [aws_security_group.metadata_alb_security_group[0].id]
164+
security_groups = [aws_security_group.metadata_alb_security_group.id]
179165

180166
tags = var.standard_tags
181167
}
182168

183169
resource "aws_lb_target_group" "alb_main" {
184-
count = var.setup_alb ? 1 : 0
185170
name = "${var.resource_prefix}alb-mdtg${var.resource_suffix}"
186171
port = 8080
187172
protocol = "HTTP"
@@ -203,7 +188,6 @@ resource "aws_lb_target_group" "alb_main" {
203188

204189

205190
resource "aws_lb_target_group" "alb_db_migrate" {
206-
count = var.setup_alb ? 1 : 0
207191
name = "${var.resource_prefix}alb-dbtg${var.resource_suffix}"
208192
port = 8082
209193
protocol = "HTTP"
@@ -224,31 +208,28 @@ resource "aws_lb_target_group" "alb_db_migrate" {
224208
}
225209

226210
resource "aws_lb_listener" "alb_main" {
227-
count = var.setup_alb ? 1 : 0
228-
load_balancer_arn = aws_lb.alb[0].arn
211+
load_balancer_arn = aws_lb.alb.arn
229212
port = "80"
230213
protocol = "HTTP"
231214

232215
default_action {
233216
type = "forward"
234-
target_group_arn = aws_lb_target_group.alb_main[0].arn
217+
target_group_arn = aws_lb_target_group.alb_main.arn
235218
}
236219
}
237220

238221
resource "aws_lb_listener" "alb_db_migrate" {
239-
count = var.setup_alb ? 1 : 0
240-
load_balancer_arn = aws_lb.alb[0].arn
222+
load_balancer_arn = aws_lb.alb.arn
241223
port = "8082"
242224
protocol = "HTTP"
243225

244226
default_action {
245227
type = "forward"
246-
target_group_arn = aws_lb_target_group.alb_db_migrate[0].arn
228+
target_group_arn = aws_lb_target_group.alb_db_migrate.arn
247229
}
248230
}
249231

250232
resource "aws_lb" "apigw_nlb" {
251-
count = var.setup_alb && var.point_api_gateway_to_alb ? 1 : 0
252233
name = "${var.resource_prefix}apigw-nlb${var.resource_suffix}"
253234
internal = true
254235
load_balancer_type = "network"
@@ -258,7 +239,6 @@ resource "aws_lb" "apigw_nlb" {
258239
}
259240

260241
resource "aws_lb_target_group" "apigw_metadata" {
261-
count = var.setup_alb && var.point_api_gateway_to_alb ? 1 : 0
262242
name = "${var.resource_prefix}apigw-mdtg${var.resource_suffix}"
263243
port = 80
264244
protocol = "TCP"
@@ -276,13 +256,11 @@ resource "aws_lb_target_group" "apigw_metadata" {
276256
}
277257

278258
resource "aws_lb_target_group_attachment" "apigw_metadata" {
279-
count = var.setup_alb && var.point_api_gateway_to_alb ? 1 : 0
280-
target_group_arn = aws_lb_target_group.apigw_metadata[0].arn
281-
target_id = aws_lb.alb[0].arn
259+
target_group_arn = aws_lb_target_group.apigw_metadata.arn
260+
target_id = aws_lb.alb.arn
282261
}
283262

284263
resource "aws_lb_target_group" "apigw_db_migrate" {
285-
count = var.setup_alb && var.point_api_gateway_to_alb ? 1 : 0
286264
name = "${var.resource_prefix}apigw-dbtg${var.resource_suffix}"
287265
port = 8082
288266
protocol = "TCP"
@@ -301,31 +279,28 @@ resource "aws_lb_target_group" "apigw_db_migrate" {
301279
}
302280

303281
resource "aws_lb_target_group_attachment" "apigw_db_migrate" {
304-
count = var.setup_alb && var.point_api_gateway_to_alb ? 1 : 0
305-
target_group_arn = aws_lb_target_group.apigw_db_migrate[0].arn
306-
target_id = aws_lb.alb[0].arn
282+
target_group_arn = aws_lb_target_group.apigw_db_migrate.arn
283+
target_id = aws_lb.alb.arn
307284
}
308285

309286
resource "aws_lb_listener" "apigw_metadata" {
310-
count = var.setup_alb && var.point_api_gateway_to_alb ? 1 : 0
311-
load_balancer_arn = aws_lb.apigw_nlb[0].arn
287+
load_balancer_arn = aws_lb.apigw_nlb.arn
312288
port = "80"
313289
protocol = "TCP"
314290

315291
default_action {
316292
type = "forward"
317-
target_group_arn = aws_lb_target_group.apigw_metadata[0].arn
293+
target_group_arn = aws_lb_target_group.apigw_metadata.arn
318294
}
319295
}
320296

321297
resource "aws_lb_listener" "apigw_db_migrate" {
322-
count = var.setup_alb && var.point_api_gateway_to_alb ? 1 : 0
323-
load_balancer_arn = aws_lb.apigw_nlb[0].arn
298+
load_balancer_arn = aws_lb.apigw_nlb.arn
324299
port = "8082"
325300
protocol = "TCP"
326301

327302
default_action {
328303
type = "forward"
329-
target_group_arn = aws_lb_target_group.apigw_db_migrate[0].arn
304+
target_group_arn = aws_lb_target_group.apigw_db_migrate.arn
330305
}
331306
}

modules/metadata-service/ecs.tf

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ EOF
6868
}
6969

7070
locals {
71-
alb_ports = var.setup_alb ? [8080, 8082] : []
72-
alb_target_groups = var.setup_alb ? [aws_lb_target_group.alb_main[0].arn, aws_lb_target_group.alb_db_migrate[0].arn] : []
71+
alb_ports = [8080, 8082]
72+
alb_target_groups = [aws_lb_target_group.alb_main.arn, aws_lb_target_group.alb_db_migrate.arn]
7373
}
7474

7575
resource "aws_ecs_service" "this" {
@@ -85,18 +85,6 @@ resource "aws_ecs_service" "this" {
8585
subnets = [var.subnet1_id, var.subnet2_id]
8686
}
8787

88-
load_balancer {
89-
target_group_arn = aws_lb_target_group.this.arn
90-
container_name = "${var.resource_prefix}service${var.resource_suffix}"
91-
container_port = 8080
92-
}
93-
94-
load_balancer {
95-
target_group_arn = aws_lb_target_group.db_migrate.arn
96-
container_name = "${var.resource_prefix}service${var.resource_suffix}"
97-
container_port = 8082
98-
}
99-
10088
dynamic "load_balancer" {
10189
for_each = local.alb_ports
10290
content {

modules/metadata-service/lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ resource "aws_lambda_function" "db_migrate_lambda" {
126126

127127
environment {
128128
variables = {
129-
MD_LB_ADDRESS = "http://${aws_lb.this.dns_name}:8082"
129+
MD_LB_ADDRESS = "http://${aws_lb.alb.dns_name}:8082"
130130
}
131131
}
132132

modules/metadata-service/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
output "METAFLOW_SERVICE_INTERNAL_URL" {
2-
value = "http://${aws_lb.this.dns_name}/"
2+
value = "http://${aws_lb.alb.dns_name}/"
33
description = "URL for Metadata Service (Accessible in VPC)"
44
}
55

@@ -34,6 +34,6 @@ output "metadata_svc_ecs_task_role_arn" {
3434
}
3535

3636
output "network_load_balancer_dns_name" {
37-
value = aws_lb.this.dns_name
37+
value = aws_lb.alb.dns_name
3838
description = "The DNS addressable name for the Network Load Balancer that accepts requests and forwards them to our Fargate MetaData service instance(s)"
3939
}

modules/metadata-service/variables.tf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,3 @@ variable "with_public_ip" {
132132
default = false
133133
description = "Enable private IP by default"
134134
}
135-
136-
variable "setup_alb" {
137-
type = bool
138-
default = false
139-
description = "Also setup an ALB for metadata service (will be default once we deprecate NLB completely)"
140-
}
141-
142-
variable "point_api_gateway_to_alb" {
143-
type = bool
144-
default = false
145-
description = "if setup_alb and point_api_gateway_to_alb is true, API gateway will point to ALB instead of NLB"
146-
}

0 commit comments

Comments
 (0)