Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot recreate database instance due to create_before_destroy set to true on the cluster instance #257

Open
nitrocode opened this issue Mar 14, 2025 · 2 comments · May be fixed by #258
Open
Labels
bug 🐛 An issue with the system

Comments

@nitrocode
Copy link
Member

nitrocode commented Mar 14, 2025

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.

resource "aws_rds_cluster_instance" "default" {
count = local.cluster_instance_count
identifier = "${module.rds_identifier[0].id}-${count.index + 1}"

resource "aws_rds_cluster_parameter_group" "default" {
count = local.enabled ? 1 : 0
name_prefix = var.parameter_group_name_prefix_enabled ? "${coalesce(var.rds_cluster_parameter_group_name, module.this.id)}${module.this.delimiter}" : null
name = !var.parameter_group_name_prefix_enabled ? coalesce(var.rds_cluster_parameter_group_name, module.this.id) : null

resource "aws_db_parameter_group" "default" {
count = local.enabled ? 1 : 0
name_prefix = var.parameter_group_name_prefix_enabled ? "${coalesce(var.db_parameter_group_name, module.this.id)}${module.this.delimiter}" : null
name = !var.parameter_group_name_prefix_enabled ? coalesce(var.db_parameter_group_name, module.this.id) : null

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_prefix for aws_rds_cluster_instance
  • Remove create_before_destroy = true flag for these resources

Expected Behavior

Recreation without naming conflict

Steps to Reproduce

  1. terraform apply an empty database
  2. provide the snapshot identifier arn which will result in a recreation
  3. terraform apply

You should see the error now

Screenshots

N/A

Environment

terraform 1.11.0
module v1.18.0

Additional Context

  • reopen #192 #213
  • Docs regarding the create_before_destroy flag for aws_db_parameter_group and there is no equivalent for aws_rds_cluster_instance but one can predict if there was, it would most likely recommend identifier_prefix.
@nitrocode nitrocode added the bug 🐛 An issue with the system label Mar 14, 2025
@nitrocode
Copy link
Member Author

cc @finchr since you added the flag, what do you think about this use-case ?

@nitrocode nitrocode linked a pull request Mar 14, 2025 that will close this issue
@finchr
Copy link
Contributor

finchr commented Mar 14, 2025

cc @finchr since you added the flag, what do you think about this use-case ?

I add a comment to the PR asking why we needed a prefix when we're already using a random_pet.

I'm also a little concerned with "provide the snapshot identifier arn which will result in a recreation" but don't see that this was implemented in PR #258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants