Skip to main content
Read replicas provide a read-only copy of your database that is kept in sync with the source instance via asynchronous replication. They are used to offload read traffic, enable low-downtime migrations, and serve as the source for cross-region disaster recovery.
Backups must be enabled on the source (master) instance before a replica can be created. Set backup_retention_period to at least 1 on the master.

Same-region replicas

main.tf

The replicate_source_db variable

The replicate_source_db variable tells the module to create a read replica rather than a standalone instance:
  • For same-region replicas, set it to the source instance’s db_instance_identifier (a plain string like "replica-mysql-master").
  • For cross-region replicas, set it to the source instance’s db_instance_arn (a full ARN like "arn:aws:rds:eu-west-1:123456789012:db:replica-postgresql-master").
When replicate_source_db is set:
  • username, db_name, and manage_master_user_password are inherited from the source — do not set them on the replica module.
  • backup_retention_period on the replica can be 0 (automated backups of the replica are not required).
  • The password_wo write-only attribute can be used on the MySQL replica to set a standalone password in case the replica is ever promoted.

Cross-region replica (PostgreSQL)

For cross-region replication, use the db_instance_arn of the master and provide a KMS key in the replica region to encrypt the replica’s storage.
main.tf

Encrypted cross-region replicas and KMS

When the source instance is encrypted and you are creating a cross-region replica, you must supply a kms_key_id from the destination region. The source region’s KMS key cannot be used to encrypt storage in a different region. Create a new KMS key in the replica region (as shown above with module.kms) and pass its ARN to kms_key_id.
Key differences from same-region replicas:
  • replicate_source_db is set to module.master.db_instance_arn (the full ARN) instead of the identifier.
  • A dedicated aws provider alias (aws.region2) is passed to the replica module via the providers argument.
  • create_db_parameter_group = false — the parameter group is inherited from the source; creating a new one in the replica region is only needed if you want to override parameters on the replica.
  • Separate VPC and security group resources are provisioned in the replica region.

Outputs

Both replica examples produce outputs for both the master and replica instances: