Skip to content

Commit

Permalink
Use private subnets for database when no db subnets provided
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoucgitter committed Oct 25, 2023
1 parent 078d5c3 commit ce2cc34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions modules/aws_vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ locals {
existing_database_subnets = local.existing_subnets && contains(keys(var.existing_subnet_ids), "database") ? (length(var.existing_subnet_ids["database"]) > 0 ? true : false) : false

# public_subnets = local.existing_public_subnets ? data.aws_subnet.public : aws_subnet.public # not used keeping for ref
private_subnets = local.existing_private_subnets ? data.aws_subnet.private : aws_subnet.private
database_subnets = local.existing_database_subnets ? data.aws_subnet.database : aws_subnet.database # tflint-ignore: terraform_unused_declarations
private_subnets = local.existing_private_subnets ? data.aws_subnet.private : aws_subnet.private

# Use private subnets if we are not creating db subnets and there are no existing db subnets
database_subnets = local.existing_database_subnets ? data.aws_subnet.database : element(concat(aws_subnet.database[*].id, tolist([""])), 0) != "" ? aws_subnet.database : local.private_subnets

byon_tier = var.vpc_id == null ? 0 : local.existing_private_subnets ? (var.raw_sec_group_id == null && var.cluster_security_group_id == null && var.workers_security_group_id == null) ? 2 : 3 : 1
byon_scenario = local.byon_tier
Expand Down
2 changes: 1 addition & 1 deletion modules/aws_vpc/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ output "private_subnet_cidrs" {

output "database_subnets" {
description = "List of IDs of database subnets"
value = local.existing_database_subnets ? data.aws_subnet.database[*].id : aws_subnet.database[*].id
value = local.existing_database_subnets ? data.aws_subnet.database[*].id : local.database_subnets[*].id
}

output "nat_public_ips" {
Expand Down

0 comments on commit ce2cc34

Please sign in to comment.