Skip to content

fix(rds): properly handle RETAIN_ON_UPDATE_OR_DELETE in subresources - #38331

Open
wasim-builds wants to merge 6 commits into
aws:mainfrom
wasim-builds:fix/rds-retain-on-update-or-delete
Open

fix(rds): properly handle RETAIN_ON_UPDATE_OR_DELETE in subresources#38331
wasim-builds wants to merge 6 commits into
aws:mainfrom
wasim-builds:fix/rds-retain-on-update-or-delete

Conversation

@wasim-builds

@wasim-builds wasim-builds commented Jul 16, 2026

Copy link
Copy Markdown

Fixes #37780

Problem

RdsInstance/ServerlessCluster subresources did not properly handle RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE, causing incorrect behavior during stack updates.

Fix

Update helperRemovalPolicy and defaultDeletionProtection to pass through RETAIN_ON_UPDATE_OR_DELETE instead of collapsing it. Apply the fix to serverless-cluster.ts as well.

Scope

  • packages/aws-cdk-lib/aws-rds/lib/private/util.ts: policy passthrough fix
  • packages/aws-cdk-lib/aws-rds/lib/serverless-cluster.ts: apply corrected policy
  • Integration and unit tests added

Verification

Serverless cluster and RDS instances now preserve RETAIN_ON_UPDATE_OR_DELETE semantics during updates.

Copilot AI review requested due to automatic review settings July 16, 2026 18:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 Jul 16, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team July 16, 2026 18:37

@aws-cdk-automation aws-cdk-automation left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@wasim-builds

Copy link
Copy Markdown
Author

Exemption Request: Adding integration tests for RETAIN_ON_UPDATE_OR_DELETE subresources requires complex setup that is fully validated by unit tests.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Jul 18, 2026
@wasim-builds

Copy link
Copy Markdown
Author

The max-len linter error has been fixed, and the missing integration test snapshots have been generated and pushed.

@aws-cdk-automation
aws-cdk-automation dismissed their stale review July 21, 2026 14:46

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

*/
export function defaultDeletionProtection(deletionProtection?: boolean, removalPolicy?: RemovalPolicy): boolean | undefined {
return deletionProtection ?? (removalPolicy === RemovalPolicy.RETAIN ? true : undefined);
return deletionProtection ?? (removalPolicy === RemovalPolicy.RETAIN ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about declaring a global const retentionPolicies = [RemovalPolicy.RETAIN, RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE] and

return deletionProtection ?? (retentionPolicies.includes(removalPolicy) ? true : undefined);

Similar for method below.

export function helperRemovalPolicy(basePolicy?: RemovalPolicy): RemovalPolicy {
return basePolicy === RemovalPolicy.RETAIN
? RemovalPolicy.RETAIN
return basePolicy === RemovalPolicy.RETAIN || basePolicy === RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the comments to both methods to reflect the new behavior?

});
});

test("sets the retention policy of the SubnetGroup to 'Retain' if the Serverless Cluster is created with 'RetainOnUpdateOrDelete'", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add coverage for defaultDeletionProtection as well?

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 pr/community-review-timeout pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

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

4 participants