Skip to content

Commit 4b34a1d

Browse files
authored
Merge pull request #137 from DSACMS/wbprice/simplify-subnet-setup
Wbprice/simplify subnet setup
2 parents 2ca9738 + a4589a3 commit 4b34a1d

File tree

7 files changed

+36
-44
lines changed

7 files changed

+36
-44
lines changed

infrastructure/envs/dev/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ module "api-db" {
5858
publicly_accessible = false
5959
username = "npd"
6060
db_name = "npd"
61+
db_subnet_group_name = module.networking.private_subnet_group_name
6162
vpc_security_group_ids = [module.networking.db_security_group_id]
62-
db_subnet_group_name = module.networking.db_subnet_group_name
6363
backup_retention_period = 7 # Remove automated snapshots after 7 days
6464
backup_window = "03:00-04:00" # 11PM EST
6565
}
@@ -78,8 +78,8 @@ module "etl-db" {
7878
publicly_accessible = false
7979
username = "npd_etl"
8080
db_name = "npd_etl"
81-
vpc_security_group_ids = [module.networking.db_security_group_id]
82-
db_subnet_group_name = module.networking.db_subnet_group_name
81+
db_subnet_group_name = module.networking.private_subnet_group_name
82+
vpc_security_group_ids = [module.networking.etl_db_security_group_id]
8383
backup_retention_period = 7 # Remove automated snapshots after 7 days
8484
backup_window = "03:00-04:00" # 11PM EST
8585
}
@@ -117,7 +117,7 @@ module "fhir-api" {
117117
db_instance_name = module.api-db.db_instance_name
118118
}
119119
networking = {
120-
db_subnet_ids = module.networking.db_subnet_ids
120+
private_subnet_ids = module.networking.private_subnet_ids
121121
public_subnet_ids = module.networking.public_subnet_ids
122122
alb_security_group_id = module.networking.alb_security_group_id
123123
api_security_group_id = module.networking.api_security_group_id
@@ -139,10 +139,10 @@ module "etl" {
139139
db_instance_name = module.etl-db.db_instance_name
140140
}
141141
networking = {
142-
etl_subnet_ids = module.networking.etl_subnet_ids
143-
etl_security_group_id = module.networking.etl_security_group_id
144-
etl_alb_security_group_id = module.networking.etl_alb_security_group_id
142+
private_subnet_ids = module.networking.private_subnet_ids
145143
public_subnet_ids = module.networking.public_subnet_ids
144+
etl_alb_security_group_id = module.networking.etl_alb_security_group_id
145+
etl_security_group_id = module.networking.etl_security_group_id
146146
vpc_id = module.networking.vpc_id
147147
}
148148
}
@@ -159,6 +159,6 @@ module "github-actions" {
159159

160160
account_name = local.account_name
161161
vpc_id = module.networking.vpc_id
162-
subnet_id = module.networking.etl_subnet_ids[0]
162+
subnet_id = module.networking.private_subnet_ids[0]
163163
}
164164

infrastructure/modules/etl/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ resource "aws_ecs_service" "dagster_daemon" {
176176
enable_execute_command = true
177177

178178
network_configuration {
179-
subnets = var.networking.etl_subnet_ids
179+
subnets = var.networking.private_subnet_ids
180180
security_groups = [var.networking.etl_security_group_id]
181181
}
182182

@@ -243,7 +243,7 @@ resource "aws_ecs_service" "dagster-ui" {
243243
enable_execute_command = true
244244

245245
network_configuration {
246-
subnets = var.networking.etl_subnet_ids
246+
subnets = var.networking.private_subnet_ids
247247
security_groups = [var.networking.etl_security_group_id]
248248
}
249249

infrastructure/modules/etl/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ variable "db" {
1212
}
1313
variable "networking" {
1414
type = object({
15-
etl_subnet_ids = list(string)
15+
public_subnet_ids = list(string)
16+
private_subnet_ids = list(string)
1617
etl_security_group_id = string
1718
etl_alb_security_group_id = string
18-
public_subnet_ids = list(string)
1919
vpc_id = string
2020
})
2121
}

infrastructure/modules/fhir-api/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ resource "aws_ecs_service" "app" {
233233
desired_count = 1
234234

235235
network_configuration {
236-
subnets = var.networking.db_subnet_ids
236+
subnets = var.networking.private_subnet_ids
237237
security_groups = [var.networking.api_security_group_id]
238238
assign_public_ip = false
239239
}

infrastructure/modules/fhir-api/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ variable "db" {
1616
}
1717
variable "networking" {
1818
type = object({
19-
db_subnet_ids = list(string)
19+
private_subnet_ids = list(string)
2020
public_subnet_ids = list(string)
2121
alb_security_group_id = string
2222
api_security_group_id = string

infrastructure/modules/networking/main.tf

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
## Subnet configuration
2-
data "aws_subnets" "database_subnets" {
2+
data "aws_subnets" "private_subnets" {
33
filter {
44
name = "tag:Name"
55
values = [
66
"${var.account_name}-private-a",
77
"${var.account_name}-private-b",
8+
"${var.account_name}-private-c"
89
]
910
}
1011
}
1112

12-
resource "aws_db_subnet_group" "database_subnets" {
13-
name = "${var.account_name}-database-subnets"
14-
subnet_ids = data.aws_subnets.database_subnets.ids
15-
}
16-
17-
data "aws_subnets" "etl_subnets" {
18-
filter {
19-
name = "tag:Name"
20-
values = [
21-
"${var.account_name}-private-c"
22-
]
23-
}
13+
resource "aws_db_subnet_group" "private_subnets" {
14+
name = "${var.account_name}-private-subnets"
15+
subnet_ids = data.aws_subnets.private_subnets.ids
2416
}
2517

2618
data "aws_subnets" "public_subnets" {
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
output "db_security_group_id" {
2+
description = "A list of security group IDs for use with the databases"
3+
value = aws_security_group.fhir_api_db_sg.id
4+
}
5+
6+
output "etl_db_security_group_id" {
27
description = "A list of security group IDs for use with the databases"
38
value = aws_security_group.fhir_etl_db_sg.id
49
}
510

6-
output "db_subnet_group_name" {
11+
output "private_subnet_ids" {
12+
description = "The private subnets used for the API"
13+
value = data.aws_subnets.private_subnets.ids
14+
}
15+
16+
output "private_subnet_group_name" {
717
description = "The name of the subnet group used with the databases"
8-
value = aws_db_subnet_group.database_subnets.name
18+
value = aws_db_subnet_group.private_subnets.name
19+
}
20+
21+
output "public_subnet_ids" {
22+
description = "IDs of public subnets"
23+
value = data.aws_subnets.public_subnets.ids
924
}
1025

1126
output "api_security_group_id" {
@@ -18,16 +33,6 @@ output "alb_security_group_id" {
1833
value = aws_security_group.fhir_api_alb_sg.id
1934
}
2035

21-
output "db_subnet_ids" {
22-
description = "The private subnets used for the API"
23-
value = data.aws_subnets.database_subnets.ids
24-
}
25-
26-
output "etl_subnet_ids" {
27-
description = "The private subnets used for the ETL processes"
28-
value = data.aws_subnets.etl_subnets.ids
29-
}
30-
3136
output "etl_alb_security_group_id" {
3237
description = "The security group for the Dagster UI load balancer"
3338
value = aws_security_group.etl_webserver_alb_sg.id
@@ -38,11 +43,6 @@ output "etl_security_group_id" {
3843
value = aws_security_group.etl_sg.id
3944
}
4045

41-
output "public_subnet_ids" {
42-
description = "IDs of public subnets"
43-
value = data.aws_subnets.public_subnets.ids
44-
}
45-
4646
output "vpc_id" {
4747
value = var.vpc_id
4848
}

0 commit comments

Comments
 (0)