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
) requiredDatabase port (e.g.
3306
forMySQL
). Used in the DB Security Group to allow access to the DB instance from the providedsecurity_group_ids
instance_class
(string
) requiredClass of RDS instance
replicate_source_db
(any
) requiredSpecifies 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)
) requiredList of subnets for the DB
vpc_id
(string
) requiredVPC ID the DB instance will be created in
Optional Variables
allow_major_version_upgrade
(string
) optionalAllow major version upgrade
Default value:
"false"
apply_immediately
(string
) optionalSpecifies whether any database modifications are applied immediately, or during the next maintenance window
Default value:
"false"
auto_minor_version_upgrade
(string
) optionalAllow automated minor version upgrade (e.g. from Postgres 9.5.3 to Postgres 9.5.4)
Default value:
"true"
backup_retention_period
(number
) optionalBackup retention period in days. Must be > 0 to enable backups
Default value:
0
backup_window
(string
) optionalWhen AWS can perform DB snapshots, can't overlap with maintenance window
Default value:
"22:00-03:00"
copy_tags_to_snapshot
(string
) optionalCopy tags from DB to a snapshot
Default value:
"true"
db_parameter
(list(string)
) optionalA list of DB parameters to apply. Note that parameters may differ from a DB family to another
Default value:
[ ]
dns_zone_id
(string
) optionalThe 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
) optionalFinal snapshot identifier e.g.: some-db-final-snapshot-2015-06-26-06-05
Default value:
""
host_name
(string
) optionalThe DB host name created in Route53
Default value:
"db"
iops
(string
) optionalThe 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
) optionalThe ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN
Default value:
""
maintenance_window
(string
) optionalThe window to perform maintenance in. Syntax: 'ddd:hh24:mi-ddd:hh24:mi' UTC
Default value:
"Mon:03:00-Mon:04:00"
monitoring_interval
(string
) optionalThe 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
) optionalSet to true if multi AZ deployment must be supported
Default value:
"false"
parameter_group_name
(string
) optionalName of the DB parameter group to associate
Default value:
""
publicly_accessible
(string
) optionalDetermines if database can be publicly available (NOT recommended)
Default value:
"false"
same_region
(string
) optionalWhether this replica is in the same region as the master.
Default value:
"false"
security_group_ids
(list(string)
) optionalThe IDs of the security groups from which to allow
ingress
traffic to the DB instanceDefault value:
[ ]
skip_final_snapshot
(string
) optionalIf true (default), no snapshot will be made before deleting DB
Default value:
"true"
snapshot_identifier
(string
) optionalSnapshot identifier e.g: rds:production-2015-06-26-06-05. If specified, the module create cluster from the snapshot
Default value:
""
storage_encrypted
(string
) optionalSpecifies whether the DB instance is encrypted. The default is false if not specified.
Default value:
"false"
storage_type
(string
) optionalOne 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.
context.tf
file of this module and part of the terraform-null-label pattern.name
(string
) requiredThe Name of the application or solution (e.g.
bastion
orportal
)
Required: YesDefault value: ``
namespace
(string
) requiredNamespace (e.g.
eg
orcp
)
Required: YesDefault value: ``
stage
(string
) requiredStage (e.g.
prod
,dev
,staging
)
Required: YesDefault value: ``
attributes
(list(string)
) optionalAdditional attributes (e.g.
1
)
Required: NoDefault value:
[ ]
delimiter
(string
) optionalDelimiter to be used between
name
,namespace
,stage
andattributes
Required: NoDefault value:
"-"
enabled
(string
) optionalSet to false to prevent the module from creating any resources
Required: NoDefault value:
"true"
tags
(map(string)
) optionalAdditional tags (e.g. map(
BusinessUnit
,XYZ
)
Required: NoDefault 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
Name | Version | Source | Description |
---|---|---|---|
dns_host_name | tags/0.2.5 | git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git | n/a |
final_snapshot_label | tags/0.3.3 | git::https://github.com/cloudposse/terraform-null-label.git | n/a |
label | tags/0.3.3 | git::https://github.com/cloudposse/terraform-null-label.git | n/a |
Resources
The following resources are used by this module:
aws_db_instance.default
(resource)aws_db_subnet_group.default
(resource)aws_kms_key.default
(resource)aws_security_group.default
(resource)aws_security_group_rule.allow_egress
(resource)aws_security_group_rule.allow_ingress
(resource)
Data Sources
The following data sources are used by this module: