Skip to main content

Module: rds-replica

Terraform module to provision AWS RDS replica instances. These are best suited for reporting purposes.

IMPORTANT It is not possible to create a read replica for a DB Instance that belongs to an Aurora DB Cluster.

Introduction

The module will create an RDS replica instance:

  • RDS Replica instance (MySQL, Postgres, SQL Server, Oracle)
  • RDS Subnet Group
  • RDS DB Security Group
  • DNS Record in Route53 for the DB endpoint

Usage

module "rds_replica" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-replica.git?ref=master"
namespace = "eg"
stage = "prod"
name = "reporting"
replicate_source_db = "eg-prod-db
dns_zone_id = "Z89FN1IW975KPE"
host_name = "reporting"
security_group_ids = ["sg-xxxxxxxx"]
database_port = 3306
multi_az = "true"
storage_type = "gp2"
storage_encrypted = "true"
instance_class = "db.t2.medium"
publicly_accessible = "false"
subnet_ids = ["subnet-xxxxxxxxx", "subnet-xxxxxxxxx"]
vpc_id = "vpc-xxxxxxxx"
auto_minor_version_upgrade = "true"
allow_major_version_upgrade = "false"
apply_immediately = "false"
maintenance_window = "Mon:03:00-Mon:04:00"
skip_final_snapshot = "false"
copy_tags_to_snapshot = "true"
backup_retention_period = 7
backup_window = "22:00-03:00"
}

Variables

Required Variables

database_port (any) required

Database port (e.g. 3306 for MySQL). Used in the DB Security Group to allow access to the DB instance from the provided security_group_ids

instance_class (string) required

Class of RDS instance

replicate_source_db (any) required

Specifies that this resource is a Replicate database, and to use this value as the source database. This correlates to the identifier of another Amazon RDS Database to replicate. Note that if you are creating a cross-region replica of an encrypted database you will also need to specify a kms_key_id. See DB Instance Replication and Working with PostgreSQL and MySQL Read Replicas for more information on using Replication.

subnet_ids (list(string)) required

List of subnets for the DB

vpc_id (string) required

VPC ID the DB instance will be created in

Optional Variables

allow_major_version_upgrade (string) optional

Allow major version upgrade


Default value: "false"

apply_immediately (string) optional

Specifies whether any database modifications are applied immediately, or during the next maintenance window


Default value: "false"

auto_minor_version_upgrade (string) optional

Allow automated minor version upgrade (e.g. from Postgres 9.5.3 to Postgres 9.5.4)


Default value: "true"

backup_retention_period (number) optional

Backup retention period in days. Must be > 0 to enable backups


Default value: 0

backup_window (string) optional

When AWS can perform DB snapshots, can't overlap with maintenance window


Default value: "22:00-03:00"

copy_tags_to_snapshot (string) optional

Copy tags from DB to a snapshot


Default value: "true"

db_parameter (list(string)) optional

A list of DB parameters to apply. Note that parameters may differ from a DB family to another


Default value: [ ]

dns_zone_id (string) optional

The ID of the DNS Zone in Route53 where a new DNS record will be created for the DB host name


Default value: ""

final_snapshot_identifier (string) optional

Final snapshot identifier e.g.: some-db-final-snapshot-2015-06-26-06-05


Default value: ""

host_name (string) optional

The DB host name created in Route53


Default value: "db"

iops (string) optional

The amount of provisioned IOPS. Setting this implies a storage_type of 'io1'. Default is 0 if rds storage type is not 'io1'


Default value: "0"

kms_key_id (string) optional

The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN


Default value: ""

maintenance_window (string) optional

The window to perform maintenance in. Syntax: 'ddd:hh24:mi-ddd:hh24:mi' UTC


Default value: "Mon:03:00-Mon:04:00"

monitoring_interval (string) optional

The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. Valid Values are 0, 1, 5, 10, 15, 30, 60.


Default value: "0"

multi_az (string) optional

Set to true if multi AZ deployment must be supported


Default value: "false"

parameter_group_name (string) optional

Name of the DB parameter group to associate


Default value: ""

publicly_accessible (string) optional

Determines if database can be publicly available (NOT recommended)


Default value: "false"

same_region (string) optional

Whether this replica is in the same region as the master.


Default value: "false"

security_group_ids (list(string)) optional

The IDs of the security groups from which to allow ingress traffic to the DB instance


Default value: [ ]

skip_final_snapshot (string) optional

If true (default), no snapshot will be made before deleting DB


Default value: "true"

snapshot_identifier (string) optional

Snapshot identifier e.g: rds:production-2015-06-26-06-05. If specified, the module create cluster from the snapshot


Default value: ""

storage_encrypted (string) optional

Specifies whether the DB instance is encrypted. The default is false if not specified.


Default value: "false"

storage_type (string) optional

One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD).


Default value: "standard"

Context Variables

The following variables are defined in the context.tf file of this module and part of the terraform-null-label pattern.

name (string) required

The Name of the application or solution (e.g. bastion or portal)
Required: Yes

Default value: ``

namespace (string) required

Namespace (e.g. eg or cp)
Required: Yes

Default value: ``

stage (string) required

Stage (e.g. prod, dev, staging)
Required: Yes

Default value: ``

attributes (list(string)) optional

Additional attributes (e.g. 1)
Required: No

Default value: [ ]

delimiter (string) optional

Delimiter to be used between name, namespace, stage and attributes
Required: No

Default value: "-"

enabled (string) optional

Set to false to prevent the module from creating any resources
Required: No

Default value: "true"

tags (map(string)) optional

Additional tags (e.g. map(BusinessUnit,XYZ)
Required: No

Default value: { }

Outputs

hostname

DNS host name of the instance

instance_address

Address of the instance

instance_endpoint

DNS Endpoint of the instance

instance_id

ID of the instance

security_group_id

ID of the Security Group

subnet_group_id

ID of the Subnet Group

Dependencies

Providers

  • aws

Modules

NameVersionSourceDescription
dns_host_nametags/0.2.5git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.gitn/a
final_snapshot_labeltags/0.3.3git::https://github.com/cloudposse/terraform-null-label.gitn/a
labeltags/0.3.3git::https://github.com/cloudposse/terraform-null-label.gitn/a

Resources

The following resources are used by this module:

Data Sources

The following data sources are used by this module: