terraform-aws-rds-cluster
terraform-aws-rds-cluster copied to clipboard
Cannot recreate database instance due to `create_before_destroy` set to `true` on the cluster instance
Describe the Bug
Hi all.
The use-cases where the database has to be recreated from a snapshot, results in an error due to a conflicting name.
I noticed that create_before_destroy = true is on both of these resources
aws_rds_cluster_instance
aws_rds_cluster_parameter_group
aws_db_parameter_group
The second aws_rds_cluster_parameter_group and third aws_db_parameter_group ones correctly has the option to either use name or name_prefix which can avoid the recreation issue, but the first aws_rds_cluster_instance only uses identifier without an option to use identifier_prefix.
https://github.com/cloudposse/terraform-aws-rds-cluster/blob/d13a56c866b80a155c052f2bb7a870e4fe1992a4/main.tf#L349-L351
https://github.com/cloudposse/terraform-aws-rds-cluster/blob/d13a56c866b80a155c052f2bb7a870e4fe1992a4/main.tf#L404-L408
https://github.com/cloudposse/terraform-aws-rds-cluster/blob/d13a56c866b80a155c052f2bb7a870e4fe1992a4/main.tf#L429-L433
Even if the flag identifier_prefix was set to presumably avoid this naming conflict issue, the flag create_before_destroy = true for these resources doesn't make sense to me since if the old database was going to be destroyed, creating a brand new one wouldn't prevent an outage. Is this flag really providing value?
Two ways to solve this and both solutions could also be employed
- Provide an option to use
identifier_prefixforaws_rds_cluster_instance - Remove
create_before_destroy = trueflag for these resources
Expected Behavior
Recreation without naming conflict
Steps to Reproduce
- terraform apply an empty database
- provide the snapshot identifier arn which will result in a recreation
- terraform apply
You should see the error now
Screenshots
N/A
Environment
terraform 1.11.0 module v1.18.0
Additional Context
- https://github.com/cloudposse/terraform-aws-rds-cluster/pull/213
- Docs regarding the
create_before_destroyflag foraws_db_parameter_groupand there is no equivalent foraws_rds_cluster_instancebut one can predict if there was, it would most likely recommendidentifier_prefix.