chore(rds): inherit RemovalPolicy in auto-created DatabaseCluster ParameterGroup #35275
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Issue # (if applicable)
Closes #35273.
Reason for this change
When a
DatabaseClusteris configured with custom parameters using theparametersproperty, the CDK automatically creates aParameterGroupresource. However, this auto-createdParameterGroupwas not inheriting the cluster'sRemovalPolicysetting, causing CloudFormation stack deletion failures.Problem: If a
DatabaseClusterhasremovalPolicy: RemovalPolicy.RETAINand uses theparametersproperty, the auto-createdParameterGroupwould have the default deletion policy. When attempting to delete the CloudFormation stack, the deletion would fail with an error like "Parameter Group is still in use by database instances" because the cluster was retained but the parameter group was being deleted.Impact: This prevents users from successfully deleting CloudFormation stacks containing RDS clusters with custom parameters and retention policies, requiring manual cleanup of parameter groups.
Description of changes
This change ensures that auto-created
ParameterGroupresources inherit the parentDatabaseCluster'sRemovalPolicyby adding a single line to the parameter group creation logic:removalPolicy: helperRemovalPolicy(props.removalPolicy)to the auto-createdParameterGroupconstructor inDatabaseClusterhelperRemovalPolicy()utility function, following the same pattern used for other auto-created resources likeSubnetGroupparametersprop is used without explicitparameterGroup)ParameterGroupbehavior or public APIsDesign Decision: The implementation follows the established CDK pattern where helper resources inherit policies from their parent constructs. This ensures consistent behavior across all auto-created resources in the RDS module.
Alternative Considered: We could have made this configurable via a separate property, but that would complicate the API unnecessarily when the inheritance behavior is the expected and logical default.
Describe any new or updated permissions being added
N/A - This change only affects CloudFormation resource deletion policies, not IAM permissions.
Description of how you validated changes
Unit Tests: Added comprehensive test coverage for
RemovalPolicyinheritance:RemovalPolicy.RETAIN→ Parameter Group getsDeletionPolicy: RetainRemovalPolicy.SNAPSHOT→ Parameter Group getsDeletionPolicy: DeleteRemovalPolicy.DESTROY→ Parameter Group getsDeletionPolicy: DeleteUnit Testing: Unit tests verify that the generated CloudFormation templates include the correct
DeletionPolicyandUpdateReplacePolicyattributes on auto-createdAWS::RDS::DBClusterParameterGroupresources.Regression Testing: Ran the complete RDS test suite to ensure existing functionality remains unchanged, including:
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license