diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 0ac5553e6..073d970a1 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -44,6 +44,7 @@ module "vpc" { intra_subnet_names = [] create_database_subnet_group = false + create_intra_subnet_group = false manage_default_network_acl = false manage_default_route_table = false manage_default_security_group = false diff --git a/main.tf b/main.tf index 618aa2c10..fffab6578 100644 --- a/main.tf +++ b/main.tf @@ -859,6 +859,22 @@ resource "aws_subnet" "intra" { ) } +resource "aws_db_subnet_group" "intra" { + count = local.create_intra_subnets && var.create_intra_subnet_group ? 1 : 0 + + name = lower(coalesce(var.intra_subnet_group_name, "${var.name}-intra")) + description = "Intra subnet group for ${var.name}" + subnet_ids = aws_subnet.intra[*].id + + tags = merge( + { + "Name" = lower(coalesce(var.intra_subnet_group_name, "${var.name}-intra")) + }, + var.tags, + var.intra_subnet_group_tags, + ) +} + locals { num_intra_route_tables = var.create_multiple_intra_route_tables ? local.len_intra_subnets : 1 } diff --git a/outputs.tf b/outputs.tf index 1d1d2783a..da70ef3d4 100644 --- a/outputs.tf +++ b/outputs.tf @@ -505,6 +505,17 @@ output "intra_network_acl_arn" { value = try(aws_network_acl.intra[0].arn, null) } +output "intra_subnet_group" { + description = "ID of intra subnet group" + value = try(aws_db_subnet_group.intra[0].id, null) +} + +output "intra_subnet_group_name" { + description = "Name of intra subnet group" + value = try(aws_db_subnet_group.intra[0].name, null) +} + + ################################################################################ # NAT Gateway ################################################################################ diff --git a/variables.tf b/variables.tf index d8338267a..49525433b 100644 --- a/variables.tf +++ b/variables.tf @@ -992,6 +992,24 @@ variable "intra_route_table_tags" { default = {} } +variable "create_intra_subnet_group" { + description = "Controls if RDS subnet group should be created (n.b. intra_subnets must also be set)" + type = bool + default = true +} + +variable "intra_subnet_group_name" { + description = "Name of intra subnet group" + type = string + default = null +} + +variable "intra_subnet_group_tags" { + description = "Additional tags for the intra subnet group" + type = map(string) + default = {} +} + ################################################################################ # Intra Network ACLs ################################################################################