Skip to main content
The db_subnet_group submodule creates an aws_db_subnet_group that spans a list of VPC subnets. DB instances must be associated with a subnet group to run within a VPC.

Source

./modules/db_subnet_group

Usage

Use this submodule standalone when you want to manage a subnet group separately from a DB instance, or share it across multiple instances:
module "db_subnet_group" {
  source  = "terraform-aws-modules/rds/aws//modules/db_subnet_group"
  version = "~> 7.0"

  name            = "my-db-subnet-group"
  use_name_prefix = false
  description     = "Subnet group for production databases"
  subnet_ids      = ["subnet-0abc123", "subnet-0def456", "subnet-0ghi789"]

  tags = {
    Environment = "production"
    Team        = "platform"
  }
}
Then reference the output in a DB instance:
module "db" {
  source  = "terraform-aws-modules/rds/aws"
  version = "~> 7.0"

  identifier             = "mydb"
  create_db_subnet_group = false
  db_subnet_group_name   = module.db_subnet_group.db_subnet_group_id

  # ... other variables
}

Input variables

create
bool
Whether to create the subnet group resource. Set to false to skip all resource creation.Default: true
name
string
The name of the DB subnet group. When use_name_prefix is true, this is used as a prefix.Default: ""
use_name_prefix
bool
Determines whether to use name as-is or create a unique name beginning with name as the prefix.Default: true
description
string
The description of the DB subnet group.Default: null
subnet_ids
list(string)
A list of VPC subnet IDs for the subnet group. At least two subnets in separate Availability Zones are recommended for high availability.Default: []
region
string
Region where the subnet group will be managed. Defaults to the region set in the provider configuration.Default: null
tags
map(string)
A mapping of tags to assign to the DB subnet group resource.Default: {}

Outputs

db_subnet_group_id
string
The name (ID) of the DB subnet group. Pass this to the db_subnet_group_name input of a DB instance.
db_subnet_group_arn
string
The ARN of the DB subnet group.

Build docs developers (and LLMs) love