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

aws_db_parameter_group: set lifecycle.create_before_destroy = true #337

Conversation

flokli
Copy link

@flokli flokli commented Nov 10, 2022

Description

This allows importing paramter groups, without failing with the following error message:

Error: Error deleting DB parameter group: InvalidDBParameterGroupState: One or more database instances are still members of this parameter group foo-postgres12-parameter-group, so the group cannot be deleted
status code: 400, request id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Motivation and Context

I previously used db_cluster_parameter_group_name and db_parameter_group_name to point to some externally-created parameter group names.

While trying to update the engine_version, it failed with some incompatibilities, so I wanted to switch to having the terraform module create them.

I:

  • removed db_cluster_parameter_group_name
  • removed db_parameter_group_name
  • added create_db_cluster_parameter_group = true
  • added create_db_parameter_group = true
  • added `db_cluster_parameter_group_family = "aurora-postgresql12"
  • added db_parameter_group_family = "aurora-postgresql12"

I moved the pre-existing parameter groups into the module state:

tf state mv 'module.foo.aws_db_parameter_group.aurora_db_postgres12_parameter_group' 'module.foo.module.aurora.aws_db_parameter_group.this[0]'
tf state mv 'module.foo.aws_rds_cluster_parameter_group.aurora_cluster_postgres12_parameter_group' 'module.foo.module.aurora.aws_rds_cluster_parameter_group.this[0]'

Terraform tried to delete the parameter groups first, before creating the new ones:

Error: Error deleting DB parameter group: InvalidDBParameterGroupState: One or more database instances are still members of this parameter group foo-postgres12-parameter-group, so the group cannot be deleted
status code: 400, request id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Setting lifecycle.before_destroy on the lifecycle.create_before_destroy = true on the aws_db_parameter_group seems to help. Terraform first creates the new DB parameter group, and then removes the old one.

This has also been suggested in hashicorp/terraform-provider-aws#6448 (comment).

Breaking Changes

N/A

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

This allows changing the engine version, without failing with the following
error message:

 Error: Error deleting DB parameter group: InvalidDBParameterGroupState: One or more database instances are still members of this parameter group foo-postgres12-parameter-group, so the group cannot be deleted
	status code: 400, request id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
@flokli
Copy link
Author

flokli commented Nov 10, 2022

I gave up on this - apparently it's not really possible to do an engine upgrade from aurora-postgresql12 to aurora-postgresql13 at all.

I ended up replacing db_cluster_parameter_group_name and db_parameter_group_name arguments with the magic default.aurora-postgresql12 string, and then updated it to default.aurora-postgresql13 during the upgrade.

@flokli flokli closed this Nov 10, 2022
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant