Removal of RDS module
Affected versions
This upgrade is applicable if your Postgres Aurora configuration is based on
either the postgres_aurora
or postgres_aurora_serverless
modules from
Golden Path, indicated by the following setup in your configuration, pointing
to either module (or any version):
module "postgres" {
source = "git@github.com:oslokommune/golden-path-iac//terraform/modules/{postgres_aurora|postgres_aurora_serverless}"
...
}
Rationale
The initial implementation of RDS Aurora was done by wrapping
terraform-aws-rds-aurora
inside a Golden Path module. This proved to cause issues because of the
module-inside-a-module
approach.
By distributing the new args-rds-aurora module
that contains sane defaults for different setups, and a new template to use it, we achieve a greater flexibility for consumers and reduce the complexity of the overall setup.
Related issues
- Ticket:
Implement args-rds-aurora for postgres_aurora* modules
- Introduced by PR:
Use arg module for RDS Aurora and RDS Aurora serverless
Manual upgrades
Choose one of the upgrade paths below.
A - delete and re-create
If you do not need the existing database, and are ok with re-creating it from scratch:
rm {postgres_aurora|postgres_aurora_serverless}.tf
terraform apply
ok get-template {postgres_aurora|postgres_aurora_serverless}
# Update template variables inside {aurora_postgres|postgres_aurora_serverless}.tf
terraform init
terraform apply
Be careful!
This will delete your existing database!
B - moving resources
- Commit any changes to your existing setup
- Identify the existing module name:
postgres
(unless you have changed it) - Update to the new template:
ok get-template {postgres_aurora|postgres_aurora_serverless}
- Update the template accordingly
- Identify the new module name:
rds_aurora
orrds_aurora_serverless
(unless you have changed the module name after retrieving the template)
The upgrade consists of moving existing Terraform resources from their old resources to their new.
Moving state
If you have no experience with moving resources in Terraform, read up on terraform state mv
before continuing.
Execute the following commands to move the cluster and the cluster instance to the new setup, the commands assumes the following:
- Existing module name:
postgres
- New module name:
rds_aurora_serverless
- Change the commands if your configuration differs
Notify your coworkers and disable automated Terraform runs
If you are using Terraform in a collaborative environment, you must ensure that when you are using terraform state mv
for a code refactoring purpose you communicate carefully with your coworkers to ensure that nobody makes any other changes between your configuration change and your terraform state mv
command, because otherwise they might inadvertently create a plan that will destroy the old object and create a new object at the new address.
terraform state mv 'module.postgres.module.database.aws_rds_cluster.this[0]' 'module.rds_aurora_serverless.aws_rds_cluster.this[0]'
terraform state mv 'module.postgres.module.database.aws_rds_cluster_instance.this["one"]' 'module.rds_aurora_serverless.aws_rds_cluster_instance.this["one"]'
terraform state mv 'module.postgres.module.database.random_password.master_password[0]' 'module.rds_aurora_serverless.random_password.master_password[0]'
terraform state mv 'module.postgres.aws_ssm_parameter.db_endpoint' 'aws_ssm_parameter.db_endpoint'
terraform state mv 'module.postgres.aws_ssm_parameter.db_password' 'aws_ssm_parameter.db_password'
terraform state mv 'module.postgres.aws_ssm_parameter.db_username' 'aws_ssm_parameter.db_username'
terraform state mv 'module.postgres.module.database.aws_security_group.this[0]' 'module.rds_aurora_serverless.aws_security_group.this[0]'
Commit and push changes.
After upgrade
- One resource will be deleted:
module.postgres.module.database.random_id.snapshot_identifier[0]
, this is expected. No other side-effects should be observed