terraform-aws-rds-aurora

Architecture Document — Production-Grade AWS Aurora Cluster Module

Terraform ≥ 1.5.0AWS Provider ≥ 5.20.0MIT License

Executive Summary

This Terraform module deploys production-grade Amazon Aurora clusters supporting both MySQL and PostgreSQL engines. It provides a comprehensive feature set including global databases for cross-region failover, RDS Proxy for connection pooling, Activity Streams for audit compliance, auto-scaling read replicas, serverless configurations, enhanced monitoring, Performance Insights, and security best practices with KMS encryption, IAM authentication, and Secrets Manager integration.

Overview

2

Engine Support

Aurora MySQL and Aurora PostgreSQL with configurable versions

10+

Resources Managed

Cluster, instances, proxy, global DB, SG, parameter groups, monitoring, auto-scaling

35

Input Variables

Cluster, auth, network, encryption, backup, monitoring, scaling, global DB config

19

Outputs

Endpoints, ARNs, proxy, global cluster, SG, monitoring, parameter groups

Architecture Diagram

Global Database Architecture

Global Cluster
(Cross-Region)
Primary Region
Aurora Cluster
Secondary Region
Aurora Cluster

Cluster Connectivity

Application
RDS Proxy
(TLS / IAM)
Security
Group
Writer
Instance
Reader
Instance(s)

Supporting Infrastructure

DB Subnet
Group
Cluster Param
Group
Instance Param
Group
Enhanced
Monitoring
Performance
Insights
Activity
Streams

Component Breakdown

ResourcePurpose
aws_rds_global_cluster.thisGlobal database for cross-region replication and automated failover
aws_db_subnet_group.thisMulti-AZ subnet group for cluster placement (minimum 2 subnets)
aws_rds_cluster_parameter_group.thisCluster-level parameter group with dynamic parameters and lifecycle management
aws_db_parameter_group.thisInstance-level parameter group for per-instance tuning
aws_rds_cluster.thisAurora cluster with encryption, backups, IAM auth, Secrets Manager, CloudWatch logs
aws_rds_cluster_instance.thisProvisioned instances (1-15) with monitoring, Performance Insights, promotion tiers
aws_rds_cluster_activity_stream.thisReal-time database activity monitoring via Kinesis Data Streams
aws_appautoscaling_target/policyAuto-scaling read replicas based on CPU utilisation target tracking
aws_security_group.thisLeast-privilege security group limited to database port from specified sources
aws_iam_role.monitoringIAM role for Enhanced Monitoring metrics collection

Data Flow

  1. Application connects via RDS Proxy (if enabled) or directly to the cluster endpoint
  2. RDS Proxy handles connection pooling, TLS termination, and IAM authentication
  3. Security Group validates source against allowed SG IDs and CIDR blocks on database port only
  4. Writer Instance handles all write operations; changes are replicated to reader instances
  5. Reader Instances serve read-only queries via the reader endpoint with auto-scaling
  6. Auto-scaling adjusts reader count (min/max) based on CPU utilisation target (default: 70%)
  7. Global Cluster replicates data across regions with sub-second replication lag
  8. Activity Streams publish database activity events to Kinesis for audit/compliance
  9. Enhanced Monitoring collects OS-level metrics at configurable intervals (1-60 seconds)
  10. Performance Insights captures query-level performance data with configurable retention

Security Controls

Encryption at Rest

Storage encryption enabled by default. Supports customer-managed KMS keys for key rotation control.

Encryption in Transit

RDS Proxy enforces TLS by default. SSL/TLS natively supported on Aurora connections.

IAM Authentication

Enabled by default. Authenticate with IAM roles instead of database passwords.

Secrets Manager

Master password managed by Secrets Manager with automatic rotation (default: enabled).

Security Groups

Least-privilege ingress: database port only from specified SG IDs and CIDR blocks.

Activity Streams

Real-time audit trail via Kinesis. KMS-encrypted. Supports sync and async modes.

Deletion Protection

Enabled by default. Final snapshot taken on deletion unless explicitly skipped.

Private Access

Instances set to publicly_accessible = false. Only accessible within VPC.

Backup

Automated backups with 7-day retention (configurable up to 35 days). Tags copied to snapshots.

Industry Adaptation

IndustryUse CaseConfiguration Focus
Financial ServicesTransaction processing with audit trailActivity Streams (sync), Global DB, 35-day backups, KMS CMK, deletion protection
HealthcareHIPAA-compliant patient data storeIAM auth, KMS encryption, Enhanced Monitoring, no public access, SG lockdown
E-CommerceHigh-read product catalogueRDS Proxy, auto-scaling readers (2-8), Performance Insights, Aurora MySQL
SaaSMulti-tenant application databaseRDS Proxy connection pooling, Aurora PostgreSQL, auto-scaling, serverless option
GamingLow-latency session and leaderboard dataGlobal DB for latency-based routing, provisioned instances, high IOPS

Production Readiness Checklist

Configuration Reference

Key Variables

VariableTypeDefaultDescription
cluster_identifierstringAurora cluster identifier (required)
enginestringaurora-mysql or aurora-postgresql (required)
engine_versionstringEngine version (required)
engine_modestringprovisionedprovisioned or serverless
master_usernamestringMaster database username
manage_master_user_passwordbooltrueUse Secrets Manager for password
instance_countnumber2Number of cluster instances (1-15)
instance_classstringdb.r6g.largeInstance class
storage_encryptedbooltrueEnable encryption at rest
backup_retention_periodnumber7Backup retention (1-35 days)
enable_deletion_protectionbooltruePrevent accidental deletion
enable_rds_proxyboolfalseCreate RDS Proxy
enable_global_clusterboolfalseCreate global database
autoscaling_enabledboolfalseEnable read replica auto-scaling
autoscaling_target_cpunumber70Target CPU % for auto-scaling
enable_activity_streamboolfalseEnable Activity Streams

Key Outputs

OutputDescription
cluster_endpointCluster writer endpoint
reader_endpointCluster reader endpoint for read-only connections
proxy_endpointRDS Proxy endpoint (if enabled)
security_group_idSecurity group ID for the cluster
global_cluster_idGlobal cluster identifier (if enabled)
activity_stream_kinesis_stream_nameKinesis stream for activity (if enabled)

Cost Estimation

ComponentApproximate Monthly Cost
db.r6g.large (2 instances)~$400
db.r6g.xlarge (3 instances)~$1,200
db.r6g.2xlarge (3 instances)~$2,400
RDS Proxy~$150
Activity Streams~$50
Performance Insights (7 days)Free
Global database replication~$200

Deployment

module "aurora" {
  source = "kogunlowo123/rds-aurora/aws"

  cluster_identifier = "my-aurora-cluster"
  engine             = "aurora-postgresql"
  engine_version     = "15.4"

  master_username             = "dbadmin"
  manage_master_user_password = true
  database_name               = "myapp"

  vpc_id     = "vpc-0123456789abcdef0"
  subnet_ids = ["subnet-aaa", "subnet-bbb", "subnet-ccc"]

  instance_count = 2
  instance_class = "db.r6g.large"

  enable_rds_proxy       = true
  autoscaling_enabled    = true
  autoscaling_max_capacity = 5

  tags = {
    Environment = "production"
  }
}
terraform init
terraform plan
terraform apply

Links