{"id":19474108,"url":"https://github.com/happypathway/terraform-aws-rds","last_synced_at":"2026-07-21T12:30:17.210Z","repository":{"id":278459900,"uuid":"935089361","full_name":"HappyPathway/terraform-aws-rds","owner":"HappyPathway","description":"Terraform Module","archived":false,"fork":false,"pushed_at":"2025-02-19T21:35:07.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-19T22:29:43.747Z","etag":null,"topics":["module","terraform","terraform-managed"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HappyPathway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"security_group.tf","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-18T22:13:24.000Z","updated_at":"2025-02-19T21:35:10.000Z","dependencies_parsed_at":"2025-02-19T22:29:54.411Z","dependency_job_id":"c98ab097-eb60-4177-896e-7ea6e632ec64","html_url":"https://github.com/HappyPathway/terraform-aws-rds","commit_stats":null,"previous_names":["happypathway/terraform-aws-rds"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HappyPathway%2Fterraform-aws-rds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HappyPathway%2Fterraform-aws-rds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HappyPathway%2Fterraform-aws-rds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HappyPathway%2Fterraform-aws-rds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HappyPathway","download_url":"https://codeload.github.com/HappyPathway/terraform-aws-rds/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240693740,"owners_count":19842500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["module","terraform","terraform-managed"],"created_at":"2024-11-10T19:23:30.456Z","updated_at":"2026-07-21T12:30:17.142Z","avatar_url":"https://github.com/HappyPathway.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform AWS RDS Module\n\nA Terraform module to create and manage AWS RDS Aurora clusters, including global clusters, instance configurations, monitoring, and backup settings.\n\n## Architecture\n\n### Basic Aurora Cluster\n```mermaid\ngraph TD\n    subgraph VPC\n        subgraph \"Availability Zone 1\"\n            Writer[\"Primary Instance\u003cbr\u003e(Writer)\"]\n            subgraph \"Subnet 1\"\n            end\n        end\n        subgraph \"Availability Zone 2\"\n            Reader1[\"Replica Instance 1\u003cbr\u003e(Reader)\"]\n            subgraph \"Subnet 2\"\n            end\n        end\n        subgraph \"Availability Zone 3\"\n            Reader2[\"Replica Instance 2\u003cbr\u003e(Reader)\"]\n            subgraph \"Subnet 3\"\n            end\n        end\n        Writer --\u003e Reader1\n        Writer --\u003e Reader2\n    end\n    App[\"Application\"] --\u003e Writer\n    Analytics[\"Analytics Workload\"] --\u003e Reader1\n    Reporting[\"Reporting Workload\"] --\u003e Reader2\n```\n\n### Global Cluster Architecture\n```mermaid\ngraph TD\n    subgraph \"Primary Region\"\n        subgraph \"VPC 1\"\n            Primary[\"Primary Cluster\u003cbr\u003e(Read/Write)\"]\n            PR1[\"Reader 1\"]\n            PR2[\"Reader 2\"]\n            Primary --\u003e PR1\n            Primary --\u003e PR2\n        end\n    end\n    subgraph \"Secondary Region\"\n        subgraph \"VPC 2\"\n            Secondary[\"Secondary Cluster\u003cbr\u003e(Read Only)\"]\n            SR1[\"Reader 1\"]\n            SR2[\"Reader 2\"]\n            Secondary --\u003e SR1\n            Secondary --\u003e SR2\n        end\n    end\n    Primary ==\u003e Secondary\n```\n\n## Features\n\n- Aurora Cluster creation and management\n- Global cluster support\n- Multi-AZ deployment\n- Instance scaling\n- Automated backups\n- Performance Insights\n- Enhanced monitoring\n- Custom parameter groups\n- Serverless v1 and v2 support\n- S3 import/export capabilities\n- Point-in-time recovery\n- Security group management\n\n## Usage\n\n### Basic Aurora Cluster\n\n```hcl\nmodule \"aurora_cluster\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"my-aurora-cluster\"\n  engine               = \"aurora-postgresql\"\n  engine_version       = \"14.6\"\n  instance_class       = \"db.r6g.large\"\n  number_of_instances  = 2\n  \n  db_name             = \"mydb\"\n  master_username     = \"admin\"\n  master_password     = \"your-secure-password\"\n  \n  db_subnet_group_name = \"my-subnet-group\"\n  vpc_security_group_ids = [\"sg-xxxxxxxx\"]\n}\n```\n\n### Global Cluster Configuration\n\n```hcl\nmodule \"global_aurora\" {\n  source = \"path/to/module\"\n\n  create_global_cluster = true\n  global_cluster_identifier = \"my-global-cluster\"\n  engine                   = \"aurora-postgresql\"\n  engine_version           = \"14.6\"\n  \n  # Primary cluster configuration\n  create_cluster           = true\n  cluster_identifier       = \"primary-cluster\"\n  instance_class          = \"db.r6g.large\"\n  number_of_instances     = 2\n}\n```\n\n## Requirements\n\n| Name | Version |\n|------|---------|\n| terraform | \u003e= 1.0 |\n| aws | \u003e= 4.0 |\n\n## Providers\n\n| Name | Version |\n|------|---------|\n| aws | \u003e= 4.0 |\n\n## Inputs\n\n### Cluster Configuration\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|:--------:|\n| create_cluster | Whether to create an RDS cluster | bool | true | no |\n| create_global_cluster | Whether to create a global RDS cluster | bool | false | no |\n| cluster_identifier | The identifier for the RDS cluster | string | null | yes |\n| engine | The database engine to use (aurora-mysql/aurora-postgresql) | string | \"aurora-mysql\" | no |\n| engine_version | The version of the database engine | string | null | yes |\n| instance_class | The instance class for the DB instances | string | \"db.r5.large\" | no |\n| number_of_instances | Number of instances to create in the cluster | number | 1 | no |\n\n### Database Configuration\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|:--------:|\n| db_name | Name of the database to create | string | null | no |\n| master_username | Username for the master DB user | string | null | yes |\n| master_password | Password for the master DB user | string | null | yes |\n| port | Port on which the DB accepts connections | number | 3306 | no |\n\n### Backup and Maintenance\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|:--------:|\n| backup_retention_period | Backup retention period in days | number | 35 | no |\n| preferred_backup_window | Daily time range for backups | string | \"03:00-04:00\" | no |\n| preferred_maintenance_window | Weekly maintenance window | string | \"sun:05:00-sun:06:00\" | no |\n| skip_final_snapshot | Whether to skip final snapshot on deletion | bool | false | no |\n\n### Performance and Monitoring\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|:--------:|\n| performance_insights_enabled | Enable Performance Insights | bool | false | no |\n| performance_insights_retention_period | Performance Insights retention (7/731 days) | number | 7 | no |\n| monitoring_interval | Enhanced monitoring interval (0/1/5/10/15/30/60) | number | 0 | no |\n| create_monitoring_role | Create IAM role for enhanced monitoring | bool | true | no |\n\n## Outputs\n\n| Name | Description |\n|------|-------------|\n| cluster_arn | The ARN of the RDS cluster |\n| cluster_id | The ID of the RDS cluster |\n| cluster_endpoint | The cluster endpoint |\n| cluster_reader_endpoint | The cluster reader endpoint |\n| cluster_instances | List of cluster instances |\n| security_group_id | ID of the security group created |\n\n## Testing\n\nThe module includes comprehensive tests that can be run using Terraform's built-in testing framework:\n\n```bash\n# Run all tests\nterraform test\n\n# Run specific test\nterraform test -filter=create_aurora_cluster\n```\n\n## Examples\n\n### Serverless v2 Configuration\n\n```hcl\nmodule \"aurora_serverlessv2\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"serverlessv2-cluster\"\n  engine               = \"aurora-postgresql\"\n  engine_version       = \"14.6\"\n  \n  enable_serverlessv2_scaling = true\n  serverlessv2_scaling_configuration = {\n    min_capacity = 0.5\n    max_capacity = 16\n  }\n}\n```\n\n### Enhanced Monitoring\n\n```hcl\nmodule \"aurora_monitored\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"monitored-cluster\"\n  \n  monitoring_interval   = 30\n  create_monitoring_role = true\n  \n  performance_insights_enabled = true\n  performance_insights_retention_period = 731\n}\n```\n\n## Advanced Usage Examples\n\n### Multi-Region Global Cluster with Custom Endpoints\n\n```hcl\nmodule \"global_aurora_primary\" {\n  source = \"path/to/module\"\n  providers = {\n    aws = aws.primary\n  }\n\n  create_global_cluster     = true\n  create_cluster           = true\n  global_cluster_identifier = \"global-db\"\n  cluster_identifier       = \"global-db-primary\"\n  engine                  = \"aurora-postgresql\"\n  engine_version          = \"14.6\"\n  instance_class          = \"db.r6g.large\"\n  number_of_instances     = 3\n\n  create_cluster_endpoints = true\n  cluster_endpoints = {\n    reader = {\n      type             = \"READER\"\n      static_members   = [\"global-db-primary-2\", \"global-db-primary-3\"]\n      excluded_members = []\n    }\n    analytics = {\n      type             = \"READER\"\n      static_members   = [\"global-db-primary-2\"]\n      excluded_members = []\n    }\n  }\n\n  performance_insights_enabled = true\n  performance_insights_retention_period = 731\n  monitoring_interval = 1\n\n  backup_retention_period = 14\n  preferred_backup_window = \"02:00-03:00\"\n  \n  enabled_cloudwatch_logs_exports = [\"postgresql\", \"upgrade\"]\n}\n\nmodule \"global_aurora_secondary\" {\n  source = \"path/to/module\"\n  providers = {\n    aws = aws.secondary\n  }\n\n  create_cluster           = true\n  global_cluster_identifier = module.global_aurora_primary.global_cluster_id\n  cluster_identifier       = \"global-db-secondary\"\n  instance_class          = \"db.r6g.large\"\n  number_of_instances     = 2\n\n  performance_insights_enabled = true\n  monitoring_interval = 1\n}\n```\n\n### Serverless v2 with Auto Scaling and Enhanced Monitoring\n\n```hcl\nmodule \"aurora_serverlessv2\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"serverlessv2-cluster\"\n  engine               = \"aurora-postgresql\"\n  engine_version       = \"14.6\"\n  \n  enable_serverlessv2_scaling = true\n  serverlessv2_scaling_configuration = {\n    min_capacity = 0.5\n    max_capacity = 16\n  }\n\n  monitoring_interval = 1\n  create_monitoring_role = true\n  \n  performance_insights_enabled = true\n  performance_insights_retention_period = 731\n\n  enabled_cloudwatch_logs_exports = [\"postgresql\", \"upgrade\"]\n  \n  backup_retention_period = 14\n  preferred_backup_window = \"03:00-04:00\"\n  \n  scaling_configuration = {\n    auto_pause               = true\n    min_capacity            = 2\n    max_capacity            = 16\n    seconds_until_auto_pause = 300\n    timeout_action          = \"ForceApplyCapacityChange\"\n  }\n}\n```\n\n### Cross-Region Backup Replication with Encryption\n\n```hcl\nmodule \"aurora_with_backup_replication\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"replicated-backup-cluster\"\n  engine               = \"aurora-postgresql\"\n  engine_version       = \"14.6\"\n  \n  enable_automated_backups_replication = true\n  automated_backups_replication_kms_key_id = \"arn:aws:kms:us-west-2:111122223333:key/key-id\"\n  \n  storage_encrypted = true\n  kms_key_id       = \"arn:aws:kms:us-east-1:111122223333:key/key-id\"\n  \n  backup_retention_period = 14\n  preferred_backup_window = \"02:00-03:00\"\n}\n```\n\n## Security Best Practices\n\n### Network Security\n\n1. **VPC Configuration**\n   - Deploy RDS clusters in private subnets\n   - Use Network ACLs and Security Groups to restrict access\n   - Implement separate subnets for different application tiers\n\n```hcl\nmodule \"aurora_secure\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"secure-cluster\"\n  \n  db_subnet_group_name = \"private-subnet-group\"\n  vpc_security_group_ids = [aws_security_group.rds.id]\n  \n  publicly_accessible = false\n}\n```\n\n2. **Security Groups**\n   - Limit inbound access to specific CIDR blocks or security groups\n   - Avoid using overly permissive rules (0.0.0.0/0)\n   - Regularly audit security group rules\n\n```hcl\nresource \"aws_security_group\" \"rds\" {\n  name        = \"rds-sg\"\n  description = \"Security group for RDS cluster\"\n  vpc_id      = var.vpc_id\n\n  ingress {\n    from_port       = 5432\n    to_port         = 5432\n    protocol        = \"tcp\"\n    security_groups = [var.application_security_group_id]\n  }\n}\n```\n\n### Encryption and Key Management\n\n1. **Data Encryption**\n   - Enable storage encryption using KMS keys\n   - Use customer-managed KMS keys for better control\n   - Enable SSL/TLS for data in transit\n\n2. **Key Rotation**\n   - Enable automatic key rotation for KMS keys\n   - Regularly update SSL/TLS certificates\n   - Monitor certificate expiration\n\n```hcl\nmodule \"aurora_encrypted\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"encrypted-cluster\"\n  \n  storage_encrypted = true\n  kms_key_id       = aws_kms_key.rds.arn\n  \n  ca_cert_identifier = \"rds-ca-rsa4096-g1\"\n}\n```\n\n### Authentication and Access Control\n\n1. **IAM Authentication**\n   - Enable IAM database authentication\n   - Use IAM roles for applications\n   - Implement least privilege access\n\n```hcl\nmodule \"aurora_iam_auth\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"iam-auth-cluster\"\n  \n  iam_database_authentication_enabled = true\n  \n  iam_roles = {\n    s3_import = {\n      feature_name = \"s3Import\"\n      role_arn    = aws_iam_role.rds_s3_import.arn\n    }\n  }\n}\n```\n\n2. **Password Management**\n   - Use AWS Secrets Manager for password rotation\n   - Enable manage_master_user_password\n   - Implement strong password policies\n\n```hcl\nmodule \"aurora_managed_password\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"managed-password-cluster\"\n  \n  manage_master_user_password = true\n  master_user_secret_kms_key_id = aws_kms_key.secrets.arn\n}\n```\n\n### Monitoring and Auditing\n\n1. **Enhanced Monitoring**\n   - Enable enhanced monitoring with 1-second intervals\n   - Set up Performance Insights\n   - Configure CloudWatch Logs export\n\n2. **Audit Logging**\n   - Enable audit logging\n   - Export logs to CloudWatch\n   - Set up log retention policies\n\n```hcl\nmodule \"aurora_monitored\" {\n  source = \"path/to/module\"\n\n  create_cluster        = true\n  cluster_identifier    = \"monitored-cluster\"\n  \n  monitoring_interval   = 1\n  create_monitoring_role = true\n  \n  performance_insights_enabled = true\n  performance_insights_retention_period = 731\n  \n  enabled_cloudwatch_logs_exports = [\"audit\", \"error\", \"general\", \"slowquery\"]\n  \n  enable_activity_stream = true\n  activity_stream_mode = \"async\"\n  activity_stream_engine_native_audit_fields_included = true\n}\n```\n\n### Backup and Recovery\n\n1. **Backup Strategy**\n   - Set appropriate backup retention periods\n   - Enable cross-region backup replication\n   - Test restoration procedures regularly\n\n2. **Point-in-Time Recovery**\n   - Enable automated backups\n   - Configure backup windows during off-peak hours\n   - Implement proper snapshot management\n\n## Monitoring Best Practices\n\n### CloudWatch Metrics to Monitor\n\n1. **Performance Metrics**\n   - `AuroraReplicaLag`: Monitor replication lag between primary and replicas\n   - `CPUUtilization`: Track CPU usage across instances\n   - `FreeableMemory`: Monitor available memory\n   - `DatabaseConnections`: Track number of database connections\n   - `BufferCacheHitRatio`: Measure cache effectiveness\n\n2. **Storage Metrics**\n   - `VolumeBytesUsed`: Monitor storage usage\n   - `AuroraVolumeBytesLeftTotal`: Track remaining storage\n   - `ReadIOPS` and `WriteIOPS`: Monitor I/O operations\n   - `ReadLatency` and `WriteLatency`: Track I/O latency\n\n3. **Replica Metrics**\n   - `ReplicaLag`: Monitor replication delay\n   - `ReplicationSlotDiskUsage`: Track disk usage by replication slots\n   - `TransactionLogsDiskUsage`: Monitor transaction logs storage\n\n### CloudWatch Alarms\n\n```hcl\nresource \"aws_cloudwatch_metric_alarm\" \"replica_lag\" {\n  alarm_name          = \"aurora-replica-lag\"\n  comparison_operator = \"GreaterThanThreshold\"\n  evaluation_periods  = \"5\"\n  metric_name         = \"AuroraReplicaLag\"\n  namespace           = \"AWS/RDS\"\n  period             = \"60\"\n  statistic          = \"Average\"\n  threshold          = \"2000\"\n  alarm_description  = \"Aurora replica lag has exceeded 2 seconds\"\n  alarm_actions      = [aws_sns_topic.db_alarms.arn]\n  \n  dimensions = {\n    DBClusterIdentifier = module.aurora_cluster.cluster_id\n  }\n}\n```\n\n### Dashboard Example\n\n```hcl\nresource \"aws_cloudwatch_dashboard\" \"aurora_monitoring\" {\n  dashboard_name = \"aurora-monitoring\"\n  \n  dashboard_body = jsonencode({\n    widgets = [\n      {\n        type   = \"metric\"\n        x      = 0\n        y      = 0\n        width  = 12\n        height = 6\n        \n        properties = {\n          metrics = [\n            [\"AWS/RDS\", \"CPUUtilization\", \"DBClusterIdentifier\", \"your-cluster-id\"],\n            [\".\", \"FreeableMemory\", \".\", \".\"],\n            [\".\", \"DatabaseConnections\", \".\", \".\"]\n          ]\n          period = 300\n          stat   = \"Average\"\n          region = \"your-region\"\n          title  = \"Aurora Cluster Metrics\"\n        }\n      }\n    ]\n  })\n}\n```\n\n## Troubleshooting Guide\n\n### Common Issues and Solutions\n\n1. **Connection Issues**\n   - Check security group rules\n   - Verify subnet routing\n   - Confirm SSL certificate configuration\n   ```hcl\n   module \"aurora_cluster\" {\n     # ... other configuration ...\n     ca_cert_identifier = \"rds-ca-rsa4096-g1\"\n     publicly_accessible = false\n     vpc_security_group_ids = [aws_security_group.rds.id]\n   }\n   ```\n\n2. **Performance Problems**\n   - Scale instance class\n   - Adjust Performance Insights retention\n   - Configure proper parameter groups\n   ```hcl\n   module \"aurora_cluster\" {\n     # ... other configuration ...\n     instance_class = \"db.r6g.2xlarge\"\n     performance_insights_enabled = true\n     performance_insights_retention_period = 731\n     db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.custom.name\n   }\n   ```\n\n3. **Replication Lag**\n   - Monitor replica metrics\n   - Scale read replicas\n   - Optimize write operations\n   ```hcl\n   module \"aurora_cluster\" {\n     # ... other configuration ...\n     number_of_instances = 3\n     instance_class = \"db.r6g.2xlarge\"\n     enabled_cloudwatch_logs_exports = [\"postgresql\", \"upgrade\"]\n   }\n   ```\n\n### Logging and Debugging\n\n1. **Enhanced Logging**\n   ```hcl\n   module \"aurora_cluster\" {\n     # ... other configuration ...\n     enabled_cloudwatch_logs_exports = [\n       \"audit\",\n       \"error\",\n       \"general\",\n       \"slowquery\",\n       \"postgresql\"\n     ]\n     \n     monitoring_interval = 1\n     performance_insights_enabled = true\n   }\n   ```\n\n2. **Audit Logging**\n   ```hcl\n   module \"aurora_cluster\" {\n     # ... other configuration ...\n     enable_activity_stream = true\n     activity_stream_mode = \"async\"\n     activity_stream_engine_native_audit_fields_included = true\n   }\n   ```\n\n### Maintenance Procedures\n\n1. **Version Upgrades**\n   ```hcl\n   module \"aurora_cluster\" {\n     # ... other configuration ...\n     allow_major_version_upgrade = true\n     auto_minor_version_upgrade = true\n     preferred_maintenance_window = \"sun:05:00-sun:06:00\"\n     apply_immediately = false\n   }\n   ```\n\n2. **Backup Management**\n   ```hcl\n   module \"aurora_cluster\" {\n     # ... other configuration ...\n     backup_retention_period = 14\n     preferred_backup_window = \"03:00-04:00\"\n     skip_final_snapshot = false\n     final_snapshot_identifier = \"final-snapshot-${formatdate(\"YYYY-MM-DD\", timestamp())}\"\n   }\n   ```\n\n## Performance Optimization\n\n### Parameter Group Settings\n\n```hcl\nresource \"aws_rds_cluster_parameter_group\" \"optimized\" {\n  family = \"aurora-postgresql14\"\n  name   = \"optimized-params\"\n\n  parameter {\n    name  = \"shared_buffers\"\n    value = \"{DBInstanceClassMemory/32768}\"\n  }\n\n  parameter {\n    name  = \"max_connections\"\n    value = \"GREATEST({DBInstanceClassMemory/9531392},5000)\"\n  }\n}\n```\n\n### Read Replica Configuration\n\n```hcl\nmodule \"aurora_cluster\" {\n  # ... other configuration ...\n  \n  create_cluster_endpoints = true\n  cluster_endpoints = {\n    analytics = {\n      type             = \"READER\"\n      static_members   = [\"cluster-instance-1\", \"cluster-instance-2\"]\n      excluded_members = []\n    }\n    reporting = {\n      type             = \"READER\"\n      static_members   = [\"cluster-instance-3\"]\n      excluded_members = []\n    }\n  }\n}\n```\n\n## Disaster Recovery Patterns\n\n### Multi-Region Deployment Strategies\n\n1. **Active-Passive Global Cluster**\n```hcl\n# Primary Region (us-east-1)\nmodule \"aurora_primary\" {\n  source = \"path/to/module\"\n  providers = {\n    aws = aws.primary\n  }\n\n  create_global_cluster = true\n  global_cluster_identifier = \"global-aurora\"\n  cluster_identifier = \"primary-cluster\"\n  engine            = \"aurora-postgresql\"\n  engine_version    = \"14.6\"\n\n  backup_retention_period = 35\n  deletion_protection    = true\n  storage_encrypted     = true\n\n  # High availability configuration\n  number_of_instances   = 3\n  instance_class       = \"db.r6g.xlarge\"\n}\n\n# Secondary Region (us-west-2)\nmodule \"aurora_secondary\" {\n  source = \"path/to/module\"\n  providers = {\n    aws = aws.secondary\n  }\n\n  create_cluster = true\n  global_cluster_identifier = module.aurora_primary.global_cluster_id\n  cluster_identifier = \"secondary-cluster\"\n  \n  # Match primary region capacity\n  number_of_instances = 3\n  instance_class     = \"db.r6g.xlarge\"\n}\n```\n\n2. **Cross-Region Backup Strategy**\n```hcl\nmodule \"aurora_with_cross_region_backup\" {\n  source = \"path/to/module\"\n\n  create_cluster = true\n  cluster_identifier = \"backup-replicated-cluster\"\n  \n  # Enable cross-region backup replication\n  enable_automated_backups_replication = true\n  automated_backups_replication_kms_key_id = aws_kms_key.backup_key.arn\n  snapshot_copy_destination_region = \"us-west-2\"\n  \n  # Extended backup retention for DR\n  backup_retention_period = 35\n  preferred_backup_window = \"02:00-03:00\"\n  \n  # Ensure all backups are encrypted\n  storage_encrypted = true\n  kms_key_id       = aws_kms_key.storage_key.arn\n}\n```\n\n### Recovery Time Objective (RTO) Configurations\n\n1. **Minimal RTO Setup (\u003c 1 minute)**\n```hcl\nmodule \"aurora_minimal_rto\" {\n  source = \"path/to/module\"\n\n  create_global_cluster = true\n  global_cluster_identifier = \"minimal-rto-cluster\"\n  \n  # Ensure immediate failover capability\n  enable_global_write_forwarding = true\n  \n  # Optimize for quick recovery\n  instance_class = \"db.r6g.2xlarge\"\n  number_of_instances = 3\n  \n  # Performance optimization\n  performance_insights_enabled = true\n  monitoring_interval = 1\n}\n```\n\n2. **Cost-Optimized DR (RTO \u003c 4 hours)**\n```hcl\nmodule \"aurora_cost_optimized_dr\" {\n  source = \"path/to/module\"\n\n  create_cluster = true\n  cluster_identifier = \"cost-optimized-dr\"\n  \n  # Backup-based recovery strategy\n  backup_retention_period = 35\n  enable_automated_backups_replication = true\n  \n  # Use smaller instances for cost optimization\n  instance_class = \"db.r6g.large\"\n  number_of_instances = 2\n}\n```\n\n### Recovery Point Objective (RPO) Strategies\n\n1. **Zero RPO Configuration**\n```hcl\nmodule \"aurora_zero_rpo\" {\n  source = \"path/to/module\"\n\n  create_global_cluster = true\n  global_cluster_identifier = \"zero-rpo-cluster\"\n  \n  # Enable synchronous replication\n  engine_mode = \"provisioned\"\n  \n  # Ensure data consistency\n  storage_encrypted = true\n  deletion_protection = true\n  \n  # Maximum write performance\n  instance_class = \"db.r6g.4xlarge\"\n  number_of_instances = 3\n}\n```\n\n2. **Near-Zero RPO with Point-in-Time Recovery**\n```hcl\nmodule \"aurora_near_zero_rpo\" {\n  source = \"path/to/module\"\n\n  create_cluster = true\n  cluster_identifier = \"near-zero-rpo\"\n  \n  # Enable point-in-time recovery\n  enable_restore_to_point_in_time = true\n  restore_type = \"copy-on-write\"\n  \n  # Continuous backup configuration\n  backup_retention_period = 35\n  enabled_cloudwatch_logs_exports = [\"postgresql\", \"upgrade\"]\n  \n  # Performance monitoring\n  performance_insights_enabled = true\n  performance_insights_retention_period = 731\n}\n```\n\n### Failover Testing Procedures\n\n1. **Automated Failover Testing**\n```hcl\nmodule \"aurora_failover_testing\" {\n  source = \"path/to/module\"\n\n  create_cluster = true\n  cluster_identifier = \"failover-test-cluster\"\n  \n  # Enable automated failover testing\n  auto_minor_version_upgrade = true\n  apply_immediately = true\n  \n  # Monitoring configuration for failover events\n  monitoring_interval = 1\n  enabled_cloudwatch_logs_exports = [\"postgresql\", \"upgrade\"]\n  \n  # Optional: Custom endpoints for testing\n  create_cluster_endpoints = true\n  cluster_endpoints = {\n    test = {\n      type = \"READER\"\n      static_members = [\"failover-test-cluster-2\"]\n    }\n  }\n}\n```\n\n### Business Continuity Planning\n\n1. **Documentation and Runbooks**\n- Maintain up-to-date architecture diagrams\n- Document failover procedures\n- Regular testing of recovery procedures\n- Incident response planning\n\n2. **Regular Testing Schedule**\n- Monthly failover testing\n- Quarterly DR exercises\n- Annual full recovery testing\n\n3. **Monitoring and Alerting**\n```hcl\nresource \"aws_cloudwatch_metric_alarm\" \"failover_event\" {\n  alarm_name          = \"aurora-failover-detected\"\n  comparison_operator = \"GreaterThanThreshold\"\n  evaluation_periods  = \"1\"\n  metric_name         = \"FailoverCount\"\n  namespace           = \"AWS/RDS\"\n  period             = \"300\"\n  statistic          = \"Sum\"\n  threshold          = \"0\"\n  alarm_description  = \"Aurora cluster failover detected\"\n  alarm_actions      = [aws_sns_topic.critical_alerts.arn]\n  \n  dimensions = {\n    DBClusterIdentifier = module.aurora_cluster.cluster_id\n  }\n}\n```\n\n## License\n\nThis module is licensed under the MIT License - see the LICENSE file for details.\n\n\n[![Terraform Validation](https://github.com/HappyPathway/terraform-aws-rds/actions/workflows/terraform.yaml/badge.svg)](https://github.com/HappyPathway/terraform-aws-rds/actions/workflows/terraform.yaml)\n\n\n[![Terraform Doc](https://github.com/HappyPathway/terraform-aws-rds/actions/workflows/terraform-doc.yaml/badge.svg)](https://github.com/HappyPathway/terraform-aws-rds/actions/workflows/terraform-doc.yaml)\n\n\u003c!-- BEGIN_TF_DOCS --\u003e\n{{ .Content }}\n\u003c!-- END_TF_DOCS --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappypathway%2Fterraform-aws-rds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhappypathway%2Fterraform-aws-rds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappypathway%2Fterraform-aws-rds/lists"}