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"
}

Requirements

No requirements.

Providers

NameVersion
awsn/a

Modules

NameSourceVersion
dns_host_namegit::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.gittags/0.2.5
final_snapshot_labelgit::https://github.com/cloudposse/terraform-null-label.gittags/0.3.3
labelgit::https://github.com/cloudposse/terraform-null-label.gittags/0.3.3

Resources

NameType
aws_db_instance.defaultresource
aws_db_subnet_group.defaultresource
aws_kms_key.defaultresource
aws_security_group.defaultresource
aws_security_group_rule.allow_egressresource
aws_security_group_rule.allow_ingressresource

Inputs

NameDescriptionTypeDefaultRequired
allow_major_version_upgradeAllow major version upgradestring"false"no
apply_immediatelySpecifies whether any database modifications are applied immediately, or during the next maintenance windowstring"false"no
attributesAdditional attributes (e.g. 1)list(string)[]no
auto_minor_version_upgradeAllow automated minor version upgrade (e.g. from Postgres 9.5.3 to Postgres 9.5.4)string"true"no
backup_retention_periodBackup retention period in days. Must be > 0 to enable backupsnumber0no
backup_windowWhen AWS can perform DB snapshots, can't overlap with maintenance windowstring"22:00-03:00"no
copy_tags_to_snapshotCopy tags from DB to a snapshotstring"true"no
database_portDatabase port (_e.g._ 3306 for MySQL). Used in the DB Security Group to allow access to the DB instance from the provided security_group_idsanyn/ayes
db_parameterA list of DB parameters to apply. Note that parameters may differ from a DB family to anotherlist(string)[]no
delimiterDelimiter to be used between name, namespace, stage and attributesstring"-"no
dns_zone_idThe ID of the DNS Zone in Route53 where a new DNS record will be created for the DB host namestring""no
enabledSet to false to prevent the module from creating any resourcesstring"true"no
final_snapshot_identifierFinal snapshot identifier e.g.: some-db-final-snapshot-2015-06-26-06-05string""no
host_nameThe DB host name created in Route53string"db"no
instance_classClass of RDS instancestringn/ayes
iopsThe amount of provisioned IOPS. Setting this implies a storage_type of 'io1'. Default is 0 if rds storage type is not 'io1'string"0"no
kms_key_idThe ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARNstring""no
maintenance_windowThe window to perform maintenance in. Syntax: 'ddd:hh24:mi-ddd:hh24:mi' UTCstring"Mon:03:00-Mon:04:00"no
monitoring_intervalThe 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.string"0"no
multi_azSet to true if multi AZ deployment must be supportedstring"false"no
nameThe Name of the application or solution (e.g. bastion or portal)stringn/ayes
namespaceNamespace (e.g. eg or cp)stringn/ayes
parameter_group_nameName of the DB parameter group to associatestring""no
publicly_accessibleDetermines if database can be publicly available (NOT recommended)string"false"no
replicate_source_dbSpecifies 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.anyn/ayes
same_regionWhether this replica is in the same region as the master.string"false"no
security_group_idsThe IDs of the security groups from which to allow ingress traffic to the DB instancelist(string)[]no
skip_final_snapshotIf true (default), no snapshot will be made before deleting DBstring"true"no
snapshot_identifierSnapshot identifier e.g: rds:production-2015-06-26-06-05. If specified, the module create cluster from the snapshotstring""no
stageStage (e.g. prod, dev, staging)stringn/ayes
storage_encryptedSpecifies whether the DB instance is encrypted. The default is false if not specified.string"false"no
storage_typeOne of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD).string"standard"no
subnet_idsList of subnets for the DBlist(string)n/ayes
tagsAdditional tags (e.g. map(BusinessUnit,XYZ)map(string){}no
vpc_idVPC ID the DB instance will be created instringn/ayes

Outputs

NameDescription
hostnameDNS host name of the instance
instance_addressAddress of the instance
instance_endpointDNS Endpoint of the instance
instance_idID of the instance
security_group_idID of the Security Group
subnet_group_idID of the Subnet Group