Skip to content

fix(rds): propagate RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE to helper resources#37990

Open
suhas38222 wants to merge 1 commit into
aws:mainfrom
suhas38222:fix/rds-retain-on-update-or-delete-propagation
Open

fix(rds): propagate RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE to helper resources#37990
suhas38222 wants to merge 1 commit into
aws:mainfrom
suhas38222:fix/rds-retain-on-update-or-delete-propagation

Conversation

@suhas38222
Copy link
Copy Markdown

Issue

Closes #37780.

Reason for this change

RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE was not propagated to the helper resources (subnet groups, cluster instances) created by DatabaseCluster, DatabaseInstance, and ServerlessCluster. Three places in the RDS private utilities compared against RemovalPolicy.RETAIN only — RETAIN_ON_UPDATE_OR_DELETE silently fell through to DESTROY, leaving those child resources with no explicit deletion policy at all (CloudFormation default: Delete).

Description of changes

packages/aws-cdk-lib/aws-rds/lib/private/util.ts

  • helperRemovalPolicy: extended the condition to pass RETAIN_ON_UPDATE_OR_DELETE through as-is instead of collapsing it to DESTROY. RetainExceptOnCreate is correct here: it still permits cleanup of the helper if its own creation fails during a rollback, while retaining it on normal updates and deletes.
  • defaultDeletionProtection: extended the condition to also auto-enable deletion protection when removalPolicy is RETAIN_ON_UPDATE_OR_DELETE, consistent with the existing RETAIN behaviour.

packages/aws-cdk-lib/aws-rds/lib/serverless-cluster.ts

  • Replaced the inline props.removalPolicy === RemovalPolicy.RETAIN ? props.removalPolicy : undefined check with renderUnless(helperRemovalPolicy(props.removalPolicy), RemovalPolicy.DESTROY), bringing it in line with DatabaseCluster and DatabaseInstance.

Describe any new or updated permissions being added

None. This is a pure bug fix with no IAM or AWS service interaction.

Description of how you validated changes

Unit tests (packages/aws-cdk-lib/aws-rds/test/):

  • cluster.test.ts: added RETAIN_ON_UPDATE_OR_DELETE row to both existing test.each blocks that cover DeletionPolicy/UpdateReplacePolicy on the cluster, instance, and subnet group. Added a new test.each block verifying DeletionProtection is auto-enabled for both RETAIN and RETAIN_ON_UPDATE_OR_DELETE.
  • instance.test.ts: same additions — RETAIN_ON_UPDATE_OR_DELETE row in the existing policy propagation test, plus a new DeletionProtection auto-enable test.
  • serverless-cluster.test.ts: new test asserting the subnet group gets RetainExceptOnCreate when the cluster is created with RETAIN_ON_UPDATE_OR_DELETE.

Integration test (packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.cluster-instance-removal-policy.ts):

Creates a DatabaseCluster and a DatabaseInstance each with removalPolicy: RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE and verifies that the subnet groups and cluster instances inherit RetainExceptOnCreate. Snapshot generated locally via cdk synth.

Checklist

…r resources

Fixes aws#37780

RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE was not propagated to the helper
resources (subnet groups, cluster instances) created by DatabaseCluster,
DatabaseInstance, and ServerlessCluster. Three places in the RDS private
utilities compared against RemovalPolicy.RETAIN only, so RETAIN_ON_UPDATE_OR_DELETE
silently fell through to DESTROY, leaving child resources with no explicit
deletion policy (CloudFormation default: Delete).

Changes:
- helperRemovalPolicy: pass RETAIN_ON_UPDATE_OR_DELETE through as-is so
  helper resources receive RetainExceptOnCreate, which still allows cleanup
  if the helper's own creation fails during a rollback
- defaultDeletionProtection: auto-enable deletion protection when removalPolicy
  is RETAIN_ON_UPDATE_OR_DELETE, consistent with the existing RETAIN behaviour
- ServerlessClusterNew: replace inline RETAIN-only check with helperRemovalPolicy
  + renderUnless, consistent with DatabaseCluster and DatabaseInstance

Unit tests added for all three constructs covering the new policy value.
Integration test added as a regression guard.
@github-actions github-actions Bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rds: RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE not propagated to child resources in RDS constructs

1 participant