Skip to main content

Module: rds-cluster-instance-group

Terraform module to provision an RDS Aurora instance group for MySQL or Postgres along with a dedicated endpoint.

Use this module together with our terraform-aws-rds-cluster to provision pools of RDS instances. This is useful for creating reporting clusters that don't impact the production databases.

Supports Amazon Aurora Serverless.

Usage

Basic example

module "rds_cluster_replicas" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster-instance-group.git?ref=master"
name = "postgres"
namespace = "eg"
stage = "dev"
attributes = ["replicas"]
cluster_identifier = "eg-dev-db"
cluster_size = "2"
db_port = "5432"
instance_type = "db.r4.large"
vpc_id = "vpc-xxxxxxxx"
security_groups = ["sg-xxxxxxxx"]
subnets = ["subnet-xxxxxxxx", "subnet-xxxxxxxx"]
zone_id = "Zxxxxxxxx"
}

With cluster parameters

module "rds_cluster_reporting" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster-instance-group.git?ref=master"
cluster_size = "2"
namespace = "eg"
stage = "dev"
name = "db"
attributes = ["reporting"]
cluster_identifier = "eg-dev-db"
instance_type = "db.t2.small"
vpc_id = "vpc-xxxxxxx"
security_groups = ["sg-xxxxxxxx"]
subnets = ["subnet-xxxxxxxx", "subnet-xxxxxxxx"]
zone_id = "Zxxxxxxxx"

cluster_parameters = [
{
name = "character_set_client"
value = "utf8"
},
{
name = "character_set_connection"
value = "utf8"
},
{
name = "character_set_database"
value = "utf8"
},
{
name = "character_set_results"
value = "utf8"
},
{
name = "character_set_server"
value = "utf8"
},
{
name = "collation_connection"
value = "uft8_bin"
},
{
name = "collation_server"
value = "uft8_bin"
},
{
name = "lower_case_table_names"
value = "1"
apply_method = "pending-reboot"
},
{
name = "skip-character-set-client-handshake"
value = "1"
apply_method = "pending-reboot"
},
]
}

With enhanced monitoring

# create IAM role for monitoring
resource "aws_iam_role" "enhanced_monitoring" {
name = "rds-cluster-example-1"
assume_role_policy = "${data.aws_iam_policy_document.enhanced_monitoring.json}"
}

# Attach Amazon's managed policy for RDS enhanced monitoring
resource "aws_iam_role_policy_attachment" "enhanced_monitoring" {
role = "${aws_iam_role.enhanced_monitoring.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
}

# allow rds to assume this role
data "aws_iam_policy_document" "enhanced_monitoring" {
statement {
actions = [
"sts:AssumeRole",
]

effect = "Allow"

principals {
type = "Service"
identifiers = ["monitoring.rds.amazonaws.com"]
}
}
}

module "rds_cluster_reporting" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster-instance-group.git?ref=master"
cluster_size = "2"
namespace = "eg"
stage = "dev"
name = "db"
attributes = ["reporting"]
cluster_identifier = "eg-dev-db"
db_port = "5432"
instance_type = "db.r4.large"
vpc_id = "vpc-xxxxxxx"
security_groups = ["sg-xxxxxxxx"]
subnets = ["subnet-xxxxxxxx", "subnet-xxxxxxxx"]
zone_id = "Zxxxxxxxx"

# enable monitoring every 30 seconds
rds_monitoring_interval = "30"

# reference iam role created above
rds_monitoring_role_arn = "${aws_iam_role.enhanced_monitoring.arn}"
}

Requirements

No requirements.

Providers

NameVersion
awsn/a

Modules

NameSourceVersion
dnsgit::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.gittags/0.2.5
labelgit::https://github.com/cloudposse/terraform-null-label.gittags/0.3.5

Resources

NameType
aws_db_parameter_group.defaultresource
aws_rds_cluster_endpoint.defaultresource
aws_rds_cluster_instance.defaultresource
aws_security_group.defaultresource
aws_security_group_rule.allow_egressresource
aws_security_group_rule.allow_ingressresource
aws_security_group_rule.allow_ingress_cidrresource
aws_rds_cluster.defaultdata source

Inputs

NameDescriptionTypeDefaultRequired
allowed_cidr_blocksList of CIDR blocks allowed to accesslist[]no
apply_immediatelySpecifies whether any cluster modifications are applied immediately, or during the next maintenance windowstring"true"no
attributesAdditional attributes (e.g. 1)list
[
"replicas"
]
no
cluster_familyThe family of the DB cluster parameter groupstring"aurora5.6"no
cluster_identifierThe cluster identifierstringn/ayes
cluster_sizeNumber of DB instances to create in the clusterstring"2"no
custom_endpoint_typeThe type of the endpoint. One of: READER, ANYstring"READER"no
db_portDatabase portstring"3306"no
db_subnet_group_nameA DB subnet group to associate with this DB instance. NOTE: This must match the db_subnet_group_name of the attached aws_rds_cluster.string""no
delimiterDelimiter to be used between name, namespace, stage and attributesstring"-"no
enabledSet to false to prevent the module from creating any resourcesstring"true"no
engineThe name of the database engine to be used for this DB cluster. Valid values: aurora, aurora-mysql, aurora-postgresqlstring"aurora"no
instance_parametersList of DB instance parameters to applylist[]no
instance_typeInstance type to usestring"db.t2.small"no
nameName of the applicationstringn/ayes
namespaceNamespace (e.g. eg or cp)stringn/ayes
promotion_tierFailover Priority setting on instance level. The reader who has lower tier has higher priority to get promoted to writer (values can range from 0-15).string"15"no
publicly_accessibleSet to true if you want your cluster to be publicly accessible (such as via QuickSight)string"false"no
rds_monitoring_intervalInterval in seconds that metrics are collected, 0 to disable (values can only be 0, 1, 5, 10, 15, 30, 60)string"0"no
rds_monitoring_role_arnThe ARN for the IAM role that can send monitoring metrics to CloudWatch Logsstring""no
security_group_idsThe IDs of the security groups from which to allow ingress traffic to the DB instanceslist[]no
security_groupsList of security groups to be allowed to connect to the DB instanceslist[]no
stageStage (e.g. prod, dev, staging)stringn/ayes
storage_encryptedSpecifies whether the DB cluster is encrypted. The default is false for provisioned engine_mode and true for serverless engine_modestring"true"no
subnetsList of VPC subnet IDslistn/ayes
tagsAdditional tags (e.g. map(BusinessUnit,XYZ)map{}no
vpc_idVPC ID to create the cluster in (e.g. vpc-a22222ee)stringn/ayes
zone_idRoute53 parent zone ID. If provided (not empty), the module will create sub-domain DNS record for the cluster endpointstring""no

Outputs

NameDescription
endpointThe endpoint for the Aurora cluster, automatically load-balanced across replicas
hostnameThe DNS address for the endpoint of the Aurora cluster