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
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"
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"]
}
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
]
Parameters
-
arn
optional computed - string -
description
optional - string -
id
optional computed - string -
name
optional computed - string -
name_prefix
optional computed - string -
subnet_ids
required - set of string -
tags
optional - map from string to string
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.
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.
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.
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.
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
Type: 'AWS::RDS::DBSubnetGroup'
Properties:
DBSubnetGroupDescription: Subnets available for the RDS DB Instance
SubnetIds:
- !Select [ 0 , !Ref DBSubNetIds ]
- !Select [ 1 , !Ref DBSubNetIds ]
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: "RDS Subnet Group"
SubnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: "RDS Subnet Group"
SubnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: "RDS Subnet Group"
SubnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: "RDS Subnet Group"
SubnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
"resourceType": "AWS::RDS::DBSubnetGroup",
"name": "Is associated with DBSubnetGroup"
},
{
"resourceId": "sg-97986eee",
"resourceType": "AWS::EC2::SecurityGroup",
"Type": "AWS::RDS::DBSubnetGroup",
"Properties": {
"DBSubnetGroupDescription": "VPC Subnets for the RDS Aurora Cluster",
"SubnetIds": {
"Fn::Split": [
",",
"Type": "AWS::RDS::DBSubnetGroup",
"Properties": {
"DBSubnetGroupDescription": "VPC Subnets for the RDS Aurora Cluster",
"SubnetIds": {
"Fn::Split": [
",",
"Type": "AWS::RDS::DBSubnetGroup",
"Properties": {
"DBSubnetGroupDescription": "dbsubne-group",
"SubnetIds": [
{
"Fn::ImportValue": {
Parameters
-
DBSubnetGroupDescription
required - String -
DBSubnetGroupName
optional - String -
SubnetIds
required - List -
Tags
optional - List of Tag
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.