### Updated Terraform Configuration Example for v6.x (from v5.x) Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-6.0.md This example shows the v6.x equivalent of the v5.x configuration, highlighting the transition to `instance_class` and the `instances` map for defining cluster instances and autoscaling. ```hcl module "aurora" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 6.x" instance_class = "db.r5.large" instances = { 1 = { promotion_tier = 1 } 2 = { instance_class = "db.t3.medium" promotion_tier = 2 } autoscaling_enabled = true autoscaling_min_capacity = 2 autoscaling_max_capacity = 5 ``` -------------------------------- ### Terragrunt Example: Managing Multiple S3 Buckets Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/wrappers/README.md An example demonstrating how to manage multiple S3 buckets using the wrapper module in Terragrunt. It showcases setting default bucket configurations and defining individual bucket properties. ```hcl terraform { source = "tfr:///terraform-aws-modules/rds-aurora/aws//wrappers" # Alternative source: # source = "git::git@github.com:terraform-aws-modules/terraform-aws-rds-aurora.git//wrappers?ref=master" } inputs = { defaults = { force_destroy = true attach_elb_log_delivery_policy = true attach_lb_log_delivery_policy = true attach_deny_insecure_transport_policy = true attach_require_latest_tls_policy = true } items = { bucket1 = { bucket = "my-random-bucket-1" } bucket2 = { bucket = "my-random-bucket-2" tags = { Secure = "probably" } } } } ``` -------------------------------- ### Terraform State Move Commands for v5.x to v6.x (Specific Example) Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-6.0.md Specific Terraform state move commands tailored for migrating from a v5.x configuration to the v6.x structure, as demonstrated in the example comparison. ```bash terraform state mv 'module.aurora.aws_rds_cluster_instance.this[0]' 'module.aurora.aws_rds_cluster_instance.this["1"]' terraform state mv 'module.aurora.aws_rds_cluster_instance.this[1]' 'module.aurora.aws_rds_cluster_instance.this["2"]' terraform state mv 'module.aurora.aws_appautoscaling_policy.autoscaling_read_replica_count[0]' 'module.aurora.aws_appautoscaling_policy.this[0]' terraform state mv 'module.aurora.aws_appautoscaling_target.read_replica_count[0]' 'module.aurora.aws_appautoscaling_target.this[0]' ``` -------------------------------- ### Terraform Configuration Example for v5.x Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-6.0.md An example of a Terraform configuration using an older version (v5.x) of the rds-aurora module. This is provided for comparison to illustrate the changes required for upgrading to v6.x. ```hcl module "aurora" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 5.x" instance_type = "db.r5.large" instance_type_replica = "db.t3.medium" replica_count = 2 replica_scale_enabled = true replica_scale_min = 2 replica_scale_max = 5 ``` -------------------------------- ### Homogenous Cluster with Multiple Instances Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/README.md Configure a homogenous cluster with a specified instance class for all instances. This example creates one writer and two reader instances. ```hcl cluster_instance_class = "db.r8g.large" instances = { one = {} two = {} three = {} } ``` -------------------------------- ### Terraform Configuration for RDS Aurora v6.x Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-6.0.md Example Terraform configuration demonstrating the updated syntax for RDS Aurora clusters starting with version 6.x. This includes defining instances with specific configurations and enabling autoscaling. ```hcl module "cluster_after" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 6.0" name = "after-6.x" engine = "aurora-postgresql" engine_version = "11.9" instance_type = "db.r5.large" + instances = { 1 = { instance_class = "db.r5.2xlarge" publicly_accessible = true } 2 = { instance_class = "db.r5.2xlarge" } 3 = { identifier = "reporting" instance_class = "db.r5.large" instance_promotion_tier = 15 } } + autoscaling_enabled = true + autoscaling_min_capacity = 1 + autoscaling_max_capacity = 5 vpc_id = "vpc-12345678" subnets = ["subnet-12345678", "subnet-87654321"] allowed_security_groups = ["sg-12345678"] allowed_cidr_blocks = ["10.20.0.0/20"] storage_encrypted = true apply_immediately = true monitoring_interval = 10 db_parameter_group_name = "default" db_cluster_parameter_group_name = "default" enabled_cloudwatch_logs_exports = ["postgresql"] tags = { Environment = "dev" Terraform = "true" } } ``` -------------------------------- ### Heterogeneous Cluster for Mixed Workloads Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/README.md Create a heterogeneous cluster to support mixed-use workloads, allowing independent control over instance classes and promotion tiers. This example defines specific configurations for three instances. ```hcl cluster_instance_class = "db.r8g.large" instances = { one = { instance_class = "db.r8g.2xlarge" publicly_accessible = true } two = { identifier = "static-member-1" instance_class = "db.r8g.2xlarge" } three = { identifier = "excluded-member-1" instance_class = "db.r8g.large" promotion_tier = 15 } } ``` -------------------------------- ### DSQL Cluster Configuration Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/modules/dsql/README.md Example of configuring two DSQL clusters with peering enabled. Ensures that clusters are created with specific names, witness regions, and cross-cluster peering. ```hcl module "dsql_cluster_1" { source = "../../modules/dsql" name = "dsql-1" witness_region = "us-east-2" create_cluster_peering = true clusters = [module.dsql_cluster_2.arn] tags = { Environment = "production" } } module "dsql_cluster_2" { source = "../../modules/dsql" region = "us-east-2" name = "dsql-2" witness_region = "us-west-2" create_cluster_peering = true clusters = [module.dsql_cluster_1.arn] tags = { Environment = "production" } } ``` -------------------------------- ### Heterogeneous Cluster with Autoscaling Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/README.md Configure a heterogeneous cluster with autoscaling enabled for reader instances. This setup supports mixed workloads and scales readers between 1 and 5 instances, in addition to directly defined instances. ```hcl cluster_instance_class = "db.r8g.large" instances = { one = { instance_class = "db.r8g.2xlarge" publicly_accessible = true } two = { identifier = "static-member-1" instance_class = "db.r8g.2xlarge" } three = { identifier = "excluded-member-1" instance_class = "db.r8g.large" promotion_tier = 15 } } autoscaling_enabled = true autoscaling_min_capacity = 1 autoscaling_max_capacity = 5 ``` -------------------------------- ### Homogeneous Cluster Scaled via Autoscaling Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/README.md Configure a homogeneous cluster where readers are scaled via autoscaling. This example requires at least one writer instance and allows for 1 to 5 readers. ```hcl cluster_instance_class = "db.r8g.large" instances = { one = {} } autoscaling_enabled = true autoscaling_min_capacity = 1 autoscaling_max_capacity = 5 ``` -------------------------------- ### RDS Aurora Module Before v7.x Configuration Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-8.0.md Example configuration for the RDS Aurora module prior to version 7.x, demonstrating the use of `create_random_password`, `random_password_length`, `allowed_security_groups`, `allowed_cidr_blocks`, `security_group_egress_rules`, and `final_snapshot_identifier_prefix`. ```hcl module "cluster_before" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 7.0" # Only the affected attributes are shown create_cluster = true master_username = "admin" create_random_password = true random_password_length = 16 create_db_subnet_group = false db_subnet_group_name = module.vpc.database_subnet_group_name create_security_group = true allowed_security_groups = ["sg-12345678"] allowed_cidr_blocks = ["10.20.0.0/20"] security_group_egress_rules = { to_cidrs = { cidr_blocks = ["10.33.0.0/28"] description = "Egress to corporate printer closet" } } final_snapshot_identifier_prefix = "my-cluster-" tags = { Environment = "dev" Terraform = "true" } } ``` -------------------------------- ### Terraform Configuration Before Version 5.x Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-6.0.md This example demonstrates a Terraform configuration for the AWS RDS Aurora module using a version prior to 5.x. It highlights the use of variables like `replica_count` and `instances_parameters` that have been changed or removed in newer versions. ```hcl module "cluster_before" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 5.0" name = "before-5.x" engine = "aurora-postgresql" engine_version = "11.9" instance_type = "db.r5.large" - replica_count = 3 - instances_parameters = [ # List index should be equal to `replica_count` # Omitted keys replaced by module defaults { instance_type = "db.r5.2xlarge" publicly_accessible = true }, { instance_type = "db.r5.2xlarge" }, { instance_name = "reporting" instance_type = "db.r5.large" instance_promotion_tier = 15 } ] - autoscaling_enabled = true - autoscaling_min_capacity = 1 - autoscaling_max_capacity = 5 vpc_id = "vpc-12345678" subnets = ["subnet-12345678", "subnet-87654321"] allowed_security_groups = ["sg-12345678"] allowed_cidr_blocks = ["10.20.0.0/20"] storage_encrypted = true apply_immediately = true monitoring_interval = 10 db_parameter_group_name = "default" db_cluster_parameter_group_name = "default" enabled_cloudwatch_logs_exports = ["postgresql"] tags = { Environment = "dev" Terraform = "true" } } ``` -------------------------------- ### Terragrunt Usage for RDS Aurora Wrapper Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/wrappers/README.md Configure Terragrunt to use the RDS Aurora wrapper module. This setup is useful for managing multiple module instances when `for_each` is not directly applicable. ```hcl terraform { source = "tfr:///terraform-aws-modules/rds-aurora/aws//wrappers" # Alternative source: # source = "git::git@github.com:terraform-aws-modules/terraform-aws-rds-aurora.git//wrappers?ref=master" } inputs = { defaults = { # Default values create = true tags = { Terraform = "true" Environment = "dev" } } items = { my-item = { # omitted... can be any argument supported by the module } my-second-item = { # omitted... can be any argument supported by the module } # omitted... } } ``` -------------------------------- ### Terraform Configuration Before v9.x Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-10.0.md Example Terraform configuration for an RDS Aurora cluster using version 9.x. This shows the older attribute structure for instance class, monitoring, security groups, and parameter groups. ```hcl module "cluster" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 9.0" # Only the affected attributes are shown instance_class = "db.r8g.large" monitoring_interval = 60 security_group_rules = { vpc_ingress = { cidr_blocks = module.vpc.private_subnets_cidr_blocks } } master_password = random_password.master.result # For limitless databases create_shard_group = true compute_redundancy = 0 db_shard_group_identifier = "example" max_acu = 16 create_db_cluster_parameter_group = true db_cluster_parameter_group_name = "example" db_cluster_parameter_group_family = "aurora-postgresql16" db_cluster_parameter_group_description = "Example cluster parameter group" db_cluster_parameter_group_parameters = [ { name = "log_min_duration_statement" value = 4000 apply_method = "immediate" }, { name = "rds.force_ssl" value = 1 apply_method = "immediate" } ] create_db_parameter_group = true db_parameter_group_name = "example" db_parameter_group_family = "aurora-mysql8.0" db_parameter_group_description = "Example DB parameter group" db_parameter_group_parameters = [ { name = "connect_timeout" value = 60 apply_method = "immediate" }, ] create_db_cluster_activity_stream = true db_cluster_activity_stream_kms_key_id = module.kms.key_id db_cluster_activity_stream_mode = "async" iam_roles = { s3_import = { role_arn = aws_iam_role.s3_import.arn feature_name = "s3Import" } } tags = { Environment = "dev" Terraform = "true" } } ``` -------------------------------- ### Terraform Configuration After v10.x Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-10.0.md Example Terraform configuration for an RDS Aurora cluster using version 10.x. This demonstrates the updated attribute structure for instance class, monitoring, security groups, parameter groups, and activity streams. ```hcl module "cluster" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 10.0" # Only the affected attributes are shown cluster_instance_class = "db.r8g.large" cluster_monitoring_interval = 60 security_group_ingress_rules = { private-az1 = { cidr_ipv4 = element(module.vpc.private_subnets_cidr_blocks, 0) } private-az2 = { cidr_ipv4 = element(module.vpc.private_subnets_cidr_blocks, 1) } private-az3 = { cidr_ipv4 = element(module.vpc.private_subnets_cidr_blocks, 2) } } master_password_wo = random_password.master.result master_password_wo_version = 1 # For limitless databases shard_group = { compute_redundancy = 0 identifier = "example" max_acu = 16 } cluster_parameter_group = { name = "example" family = "aurora-postgresql16" description = "Example cluster parameter group" parameters = [ { name = "log_min_duration_statement" value = 4000 apply_method = "immediate" }, { name = "rds.force_ssl" value = 1 apply_method = "immediate" } ] } db_parameter_group = { name = "example" family = "aurora-mysql8.0" description = "Example DB parameter group" parameters = [ { name = "connect_timeout" value = 60 apply_method = "immediate" }, ] } cluster_activity_stream = { kms_key_id = module.kms.key_id mode = "async" } role_associations = { s3Import = { role_arn = aws_iam_role.s3_import.arn # feature_name = "s3Import" # same as setting value to key } } tags = { Environment = "dev" Terraform = "true" } } ``` -------------------------------- ### RDS Aurora Module After v8.x Configuration Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-8.0.md Example configuration for the RDS Aurora module after version 8.x, demonstrating the use of `create`, `manage_master_user_password`, `security_group_rules`, and `final_snapshot_identifier`. This version removes random password generation and simplifies security group rules. ```hcl module "cluster_after" { source = "terraform-aws-modules/rds-aurora/aws" version = "~> 8.0" # Only the affected attributes are shown create = true manage_master_user_password = true db_subnet_group_name = module.vpc.database_subnet_group_name security_group_rules = { cidr_ingress_ex = { cidr_blocks = ["10.20.0.0/20"] } security_group_ingress_ex = { source_security_group_id = "sg-12345678" } to_the_closet = { cidr_blocks = ["10.33.0.0/28"] description = "Egress to corporate printer closet" } } final_snapshot_identifier = "my-cluster-with-a-bit-of-something-unique" tags = { Environment = "dev" Terraform = "true" } } ``` -------------------------------- ### Create MySQL Database Container Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/examples/s3-import/README.md Steps to create a Percona Server MySQL container and log into it. ```bash docker run -d --name percona-server-mysql-5.7.12 -e MYSQL_ROOT_PASSWORD=root percona/percona-server:5.7.12 docker exec -it percona-server-mysql-5.7.12 bash mysql -u root -p # password is also root ``` -------------------------------- ### Dump Database and Upload to S3 Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/examples/s3-import/README.md Commands to create a backup directory, dump the database using Percona Xtrabackup, and move the backup to the local directory for S3 upload. ```bash mkdir -p /tmp/backup docker run --name percona-xtrabackup-2.4 --mount type=bind,src=/tmp/backup,dst=/backup --volumes-from percona-server-mysql-5.7.12 percona/percona-xtrabackup:2.4 xtrabackup --backup --data-dir=/var/lib/mysql --target-dir=/backup --user=root --password=root mv /tmp/backup ./backup ``` -------------------------------- ### Create Database and User for RDS Import Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/examples/s3-import/README.md SQL commands to create a database and a user with necessary privileges for the RDS import. ```sql CREATE DATABASE s3Import; CREATE USER 's3_import_user'@'localhost' IDENTIFIED BY 'YourPwdShouldBeLongAndSecure!'; GRANT ALL PRIVILEGES ON * . * TO 's3_import_user'@'localhost'; FLUSH PRIVILEGES; ``` -------------------------------- ### Terraform Initialization and Application Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/examples/limitless/README.md Commands to initialize, plan, and apply the Terraform configuration for the AWS RDS Aurora Limitless cluster. Remember to destroy resources when no longer needed to avoid costs. ```bash terraform init terraform plan terraform apply ``` -------------------------------- ### Terraform Configuration for DSQL Wrapper Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/wrappers/dsql/README.md This Terraform configuration demonstrates how to use the dsql module wrapper. It defines the module source and provides input values for defaults and specific items. ```hcl module "wrapper" { source = "terraform-aws-modules/rds-aurora/aws//wrappers/dsql" defaults = { # Default values create = true tags = { Terraform = "true" Environment = "dev" } } items = { my-item = { # omitted... can be any argument supported by the module } my-second-item = { # omitted... can be any argument supported by the module } # omitted... } } ``` -------------------------------- ### Terragrunt Configuration for DSQL Wrapper Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/wrappers/dsql/README.md Use this Terragrunt configuration to manage multiple instances of a module. It specifies the source of the wrapper and defines default input values and specific items. ```hcl terraform { source = "tfr:///terraform-aws-modules/rds-aurora/aws//wrappers/dsql" # Alternative source: # source = "git::git@github.com:terraform-aws-modules/terraform-aws-rds-aurora.git//wrappers/dsql?ref=master" } inputs = { defaults = { # Default values create = true tags = { Terraform = "true" Environment = "dev" } } items = { my-item = { # omitted... can be any argument supported by the module } my-second-item = { # omitted... can be any argument supported by the module } # omitted... } } ``` -------------------------------- ### Basic RDS Aurora Cluster Configuration Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/README.md This snippet demonstrates the basic configuration for creating an RDS Aurora PostgreSQL cluster with specified instances, networking, and storage settings. It includes options for enabling enhanced monitoring and cloudwatch logs. ```hcl module "cluster" { source = "terraform-aws-modules/rds-aurora/aws" name = "test-aurora-db-postgres96" engine = "aurora-postgresql" engine_version = "17.5" cluster_instance_class = "db.r8g.large" instances = { one = {} two = { instance_class = "db.r8g.2xlarge" } } vpc_id = "vpc-12345678" db_subnet_group_name = "db-subnet-group" security_group_ingress_rules = { ex1_ingress = { cidr_ipv4 = "10.20.0.0/20" } ex1_ingress = { referenced_security_group_id = "sg-12345678" } } storage_encrypted = true apply_immediately = true monitoring_interval = 10 enabled_cloudwatch_logs_exports = ["postgresql"] tags = { Environment = "dev" Terraform = "true" } } ``` -------------------------------- ### Terraform State Move Commands for v5.x to v6.x Upgrade Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-6.0.md These commands are used to migrate Terraform state from older resource references in v5.x to the new structure in v6.x. Ensure to adapt the indices and keys to match your specific cluster configuration. ```bash terraform state mv 'module.cluster_before.aws_rds_cluster_instance.this[0]' 'module.cluster_after.aws_rds_cluster_instance.this["1"]' # Note: this move will need to be made for each instance in the cluster, where `` is the instance creation index/position and is mapped to its new `` specified # in the `var.instances` map. See next line for rough pattern to follow for all instances in your cluster # terraform state mv 'module.cluster_before.aws_rds_cluster_instance.this[]' 'module.cluster_after.aws_rds_cluster_instance.this[""]' terraform state mv 'module.cluster_before.aws_appautoscaling_policy.autoscaling_read_replica_count[0]' 'module.cluster_after.aws_appautoscaling_policy.this[0]' terraform state mv 'module.cluster_before.aws_appautoscaling_target.read_replica_count[0]' 'module.cluster_after.aws_appautoscaling_target.this[0]' ``` -------------------------------- ### Homogenous Cluster with Autoscaling Enabled Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/README.md Enable autoscaling for a homogenous cluster. This configuration ensures a minimum of 2 readers and a maximum of 5 readers, in addition to the directly defined instances. ```hcl cluster_instance_class = "db.r8g.large" instances = { one = {} two = {} three = {} } autoscaling_enabled = true autoscaling_min_capacity = 2 autoscaling_max_capacity = 5 ``` -------------------------------- ### Adding Security Group Description in v6.x Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-6.0.md To prevent the re-creation of the security group managed by the module during an upgrade, add the `security_group_description` attribute with a descriptive value. ```hcl security_group_description = "Managed by Terraform" ``` -------------------------------- ### Terraform State Management for Security Group Changes Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/docs/UPGRADE-10.0.md Commands to update Terraform state when migrating from `aws_security_group_rule` to `aws_vpc_security_group_ingress_rule` and `aws_vpc_security_group_egress_rule`. These commands are necessary because the resource types have changed. ```sh terraform state rm 'module.aurora.aws_security_group_rule.this["vpc_ingress"]' terraform state import 'module.aurora.aws_vpc_security_group_ingress_rule.this["private-az1"]' 'sg-xxx' terraform state import 'module.aurora.aws_vpc_security_group_ingress_rule.this["private-az2"]' 'sg-xxx' terraform state import 'module.aurora.aws_vpc_security_group_ingress_rule.this["private-az3"]' 'sg-xxx' ``` -------------------------------- ### Basic RDS Aurora Module Configuration Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/README.md This snippet demonstrates how to configure an RDS Aurora cluster with creation disabled and specific resources like subnet groups and security groups also disabled. It's useful for scenarios where you want to manage these resources separately or disable their automatic creation. ```terraform module "cluster" { source = "terraform-aws-modules/rds-aurora/aws" # Disable creation of cluster and all resources create = false # Disable creation of subnet group - provide a subnet group create_db_subnet_group = false # Disable creation of security group - provide a security group create_security_group = false # Disable creation of monitoring IAM role - provide a role ARN create_monitoring_role = false # ... omitted } ``` -------------------------------- ### Terraform Usage for RDS Aurora Wrapper Source: https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/blob/master/wrappers/README.md Implement the RDS Aurora wrapper module within a Terraform configuration. This allows for managing multiple module instances, similar to the Terragrunt approach. ```hcl module "wrapper" { source = "terraform-aws-modules/rds-aurora/aws//wrappers" defaults = { # Default values create = true tags = { Terraform = "true" Environment = "dev" } } items = { my-item = { # omitted... can be any argument supported by the module } my-second-item = { # omitted... can be any argument supported by the module } # omitted... } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.