When to use Blue/Green deployments
Major version upgrades
Upgrade from one major engine version to another (e.g., PostgreSQL 16 to 17, MySQL 8.0 to 8.4) without a multi-hour maintenance window.
Schema changes
Apply DDL changes to large tables while the current version serves traffic, then switch over when replication catches up.
Instance class changes
Resize to a larger or smaller instance class with a short cutover window instead of a full instance replacement.
Parameter group changes
Test new parameter values on the green environment before applying them to production.
Variable
| Variable | Type | Default | Description |
|---|---|---|---|
blue_green_update | object({ enabled = optional(bool) }) | null | Enable Blue/Green deployment support on the instance. |
Limitations
manage_master_user_passwordis not supported when Blue/Green is enabled. Usepassword_woandpassword_wo_versioninstead.- Backup retention must be at least
1day. The module automatically coercesbackup_retention_periodto1whenblue_green_updateis set. - Not all engine versions and regions support Blue/Green deployments. Check the AWS documentation for the supported matrix.
- The Blue/Green deployment itself (initiating, testing, and switching over) is managed through the AWS console, CLI, or SDK — Terraform only enables the feature on the instance.
Deployment workflow
Enable Blue/Green on the instance
Add
blue_green_update = { enabled = true } to your module block and apply:Create the Blue/Green deployment in AWS
Use the AWS console or CLI to create a Blue/Green deployment. AWS clones the production (blue) instance into a staging (green) environment and sets up replication between them.
Apply and validate changes on the green environment
With the green environment running, apply your schema changes, update parameters, or let it run under test load. Monitor replication lag to ensure the green instance stays in sync.
Switch over
When you are ready, initiate the switchover. AWS promotes the green instance to primary and redirects the existing DNS endpoint. The old blue instance becomes the new standby.
Update Terraform configuration to match the new version
After switchover, update Run
engine_version (and family / major_engine_version if the major version changed) in your Terraform configuration so that the state matches reality:terraform plan to verify no unintended changes.Full example
The following examples are taken fromexamples/blue-green-deployment/main.tf.
PostgreSQL with Blue/Green
MySQL with Blue/Green
PostgreSQL logical replication requirement
PostgreSQL Blue/Green deployments require logical replication to be enabled. Add this to yourparameters: