AWS Amazon RDS Subnet Group

This page shows how to write Terraform and CloudFormation for Amazon RDS Subnet Group and write them securely.

aws_db_subnet_group (Terraform)

The Subnet Group in Amazon RDS can be configured in Terraform with the resource name aws_db_subnet_group. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

00-subnet-groups.tf#L1
resource "aws_db_subnet_group" "public" {
  name       = "public_subnets"
  subnet_ids = [aws_subnet.public_subnet[0].id, aws_subnet.public_subnet[1].id, aws_subnet.public_subnet[2].id]

  tags = {
    Name = "Public DB subnets"
db_subnet_group.tf#L1
resource "aws_db_subnet_group" "tfer--default-002D-vpc-002D-04f3b83abd7739edb" {
  description = "Created from the RDS Management Console"
  name        = "default-vpc-04f3b83abd7739edb"
  subnet_ids  = ["subnet-04a366ce1a6b5ee9f", "subnet-09be0282dd76bf790"]
}

subnet-groups.tf#L2
resource "aws_db_subnet_group" "data-subnet-group" {
  name       = "main"
  subnet_ids = [
    var.db-subnet-a-us-east-1a-id
    var.db-subnet-a-us-east-1b-id
  ]

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an RDS DB subnet group resource. > Hands-on: For an example of the aws_db_subnet_group in use, follow the Manage AWS RDS Instances tutorial on HashiCorp Learn.

Tips: Best Practices for The Other AWS Amazon RDS Resources

In addition to the aws_db_instance, AWS Amazon RDS has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_db_instance

Ensure backup retension of your RDS instance is specified

It's better to set it explicitly to reduce the risk of availability issues.

risk-label

aws_rds_cluster

Ensure backup retension of your RDS cluster is specified

It's better to set it explicitly to reduce the risk of availability issues.

risk-label

aws_rds_cluster_instance

Ensure your RDS cluster instance blocks unwanted access

It's better to limit accessibily to the minimum that is required for the application to work.

Review your AWS Amazon RDS settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::RDS::DBSubnetGroup (CloudFormation)

The DBSubnetGroup in RDS can be configured in CloudFormation with the resource name AWS::RDS::DBSubnetGroup. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

rds.yml#L33
    Type: 'AWS::RDS::DBSubnetGroup'
    Properties:
      DBSubnetGroupDescription: Subnets available for the RDS DB Instance
      SubnetIds:
        - !Select [ 0 , !Ref DBSubNetIds ]
        - !Select [ 1 , !Ref DBSubNetIds ]
ServerlessSubnetGroup.yml#L1
Type: AWS::RDS::DBSubnetGroup
Properties:
  DBSubnetGroupDescription: "RDS Subnet Group"
  SubnetIds:
    - Ref: ServerlessSubnetA
    - Ref: ServerlessSubnetB
ServerlessSubnetGroup.yml#L1
Type: AWS::RDS::DBSubnetGroup
Properties:
  DBSubnetGroupDescription: "RDS Subnet Group"
  SubnetIds:
    - Ref: ServerlessSubnetA
    - Ref: ServerlessSubnetB
ServerlessSubnetGroup.yml#L1
Type: AWS::RDS::DBSubnetGroup
Properties:
  DBSubnetGroupDescription: "RDS Subnet Group"
  SubnetIds:
    - Ref: ServerlessSubnetA
    - Ref: ServerlessSubnetB
ServerlessSubnetGroup.yml#L1
Type: AWS::RDS::DBSubnetGroup
Properties:
  DBSubnetGroupDescription: "RDS Subnet Group"
  SubnetIds:
    - Ref: ServerlessSubnetA
    - Ref: ServerlessSubnetB
546156050725_Config_us-east-1_ConfigHistory_AWS__RDS__DBInstance_20190122T113622Z_20190122T113622Z_1%20-%201.json#L9
                    "resourceType": "AWS::RDS::DBSubnetGroup",
                    "name": "Is associated with DBSubnetGroup"
                },
                {
                    "resourceId": "sg-97986eee",
                    "resourceType": "AWS::EC2::SecurityGroup",
subnet-groups.json#L3
    "Type": "AWS::RDS::DBSubnetGroup",
    "Properties": {
      "DBSubnetGroupDescription": "VPC Subnets for the RDS Aurora Cluster",
      "SubnetIds": {
        "Fn::Split": [
          ",",
subnet-groups.json#L3
    "Type": "AWS::RDS::DBSubnetGroup",
    "Properties": {
      "DBSubnetGroupDescription": "VPC Subnets for the RDS Aurora Cluster",
      "SubnetIds": {
        "Fn::Split": [
          ",",
db-subnetgroup.json#L10
            "Type": "AWS::RDS::DBSubnetGroup",
            "Properties": {
                "DBSubnetGroupDescription": "dbsubne-group",
                "SubnetIds": [
                    {
                        "Fn::ImportValue": {
546156050725_Config_us-east-1_ConfigHistory_AWS__RDS__DBInstance_20190122T113622Z_20190122T113622Z_1.json#L1

Parameters

Explanation in CloudFormation Registry

The AWS::RDS::DBSubnetGroup resource creates a database subnet group. Subnet groups must contain at least two subnets in two different Availability Zones in the same region. For more information, see Working with DB subnet groups in the Amazon RDS User Guide.

Frequently asked questions

What is AWS Amazon RDS Subnet Group?

AWS Amazon RDS Subnet Group is a resource for Amazon RDS of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon RDS Subnet Group?

For Terraform, the jakoberpf/a-cloud-guru-aws-architect-associate, TNK-2/nestjs-test and hms-dbmi/avillachlab-secure-infrastructure source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the sudusan/nested-stack, Teslenk0/lambda-examples and sathishrajendran565/Arizon-CRM source code examples are useful. See the CloudFormation Example section for further details.