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
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"
}
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"
},
]
}
# 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}"
}
Variables
Required Variables
cluster_identifier(string) requiredThe cluster identifier
subnets(list) requiredList of VPC subnet IDs
vpc_id(string) requiredVPC ID to create the cluster in (e.g.
vpc-a22222ee)
Optional Variables
allowed_cidr_blocks(list) optionalList of CIDR blocks allowed to access
Default value:
[ ]apply_immediately(string) optionalSpecifies whether any cluster modifications are applied immediately, or during the next maintenance window
Default value:
"true"cluster_family(string) optionalThe family of the DB cluster parameter group
Default value:
"aurora5.6"cluster_size(string) optionalNumber of DB instances to create in the cluster
Default value:
"2"custom_endpoint_type(string) optionalThe type of the endpoint. One of: READER, ANY
Default value:
"READER"db_port(string) optionalDatabase port
Default value:
"3306"db_subnet_group_name(string) optionalA DB subnet group to associate with this DB instance. NOTE: This must match the db_subnet_group_name of the attached aws_rds_cluster.
Default value:
""engine(string) optionalThe name of the database engine to be used for this DB cluster. Valid values:
aurora,aurora-mysql,aurora-postgresqlDefault value:
"aurora"instance_parameters(list) optionalList of DB instance parameters to apply
Default value:
[ ]instance_type(string) optionalInstance type to use
Default value:
"db.t2.small"promotion_tier(string) optionalFailover 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).
Default value:
"15"publicly_accessible(string) optionalSet to true if you want your cluster to be publicly accessible (such as via QuickSight)
Default value:
"false"rds_monitoring_interval(string) optionalInterval in seconds that metrics are collected, 0 to disable (values can only be 0, 1, 5, 10, 15, 30, 60)
Default value:
"0"rds_monitoring_role_arn(string) optionalThe ARN for the IAM role that can send monitoring metrics to CloudWatch Logs
Default value:
""security_group_ids(list) optionalThe IDs of the security groups from which to allow
ingresstraffic to the DB instancesDefault value:
[ ]security_groups(list) optionalList of security groups to be allowed to connect to the DB instances
Default value:
[ ]storage_encrypted(string) optionalSpecifies whether the DB cluster is encrypted. The default is
falseforprovisionedengine_modeandtrueforserverlessengine_modeDefault value:
"true"zone_id(string) optionalRoute53 parent zone ID. If provided (not empty), the module will create sub-domain DNS record for the cluster endpoint
Default value:
""
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) requiredName of the application
Required: YesDefault value: ``
namespace(string) requiredNamespace (e.g.
egorcp)
Required: YesDefault value: ``
stage(string) requiredStage (e.g.
prod,dev,staging)
Required: YesDefault value: ``
attributes(list) optionalAdditional attributes (e.g.
1)
Required: NoDefault value:
[
"replicas"
]delimiter(string) optionalDelimiter to be used between
name,namespace,stageandattributes
Required: NoDefault value:
"-"enabled(string) optionalSet to false to prevent the module from creating any resources
Required: NoDefault value:
"true"tags(map) optionalAdditional tags (e.g. map(
BusinessUnit,XYZ)
Required: NoDefault value:
{ }
Outputs
endpointThe endpoint for the Aurora cluster, automatically load-balanced across replicas
hostnameThe DNS address for the endpoint of the Aurora cluster
Dependencies
Providers
aws
Modules
| Name | Version | Source | Description |
|---|---|---|---|
dns | tags/0.2.5 | git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git | n/a |
label | tags/0.3.5 | git::https://github.com/cloudposse/terraform-null-label.git | n/a |
Resources
The following resources are used by this module:
aws_db_parameter_group.default(resource)aws_rds_cluster_endpoint.default(resource)aws_rds_cluster_instance.default(resource)aws_security_group.default(resource)aws_security_group_rule.allow_egress(resource)aws_security_group_rule.allow_ingress(resource)aws_security_group_rule.allow_ingress_cidr(resource)
Data Sources
The following data sources are used by this module:
aws_rds_cluster.default(data source)