secretsmanager: Removal Policy set on the secret is not applied to the Resource Policy of the secret #30408
Labels
@aws-cdk/aws-secretsmanager
Related to AWS Secrets Manager
bug
This issue is a bug.
closed-for-staleness
This issue was automatically closed because it hadn't received any attention in a while.
response-requested
Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Describe the bug
If
removalPolicy
of a secret is set to retain, that is not propagated toResourcePolicy
created/updated for that secret by callingaddToResourcePolicy
.Expected Behavior
When
removalPolicy
is set toRETAIN
and secret resource removed from CDK code, I expected thatResourcePolicy
of that secret is also retained.Current Behavior
When
removalPolicy
is set toRETAIN
, and secret resource is removed from CDK code,ResourcePolicy
of the secret is deleted.Reproduction Steps
To replicate this, first create a Secret with a custom resource policy.
Change CDK code and remove the above snipped.
Expectation is that both secret and policy remain in AWS account after deploying.
Possible Solution
removalPolicy
is not applied to theResourcePolicy
construct inaddToResourcePolicy
function.https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-secretsmanager/lib/secret.ts#L438
applyRemovalPolicy
does not consider secrets resource policyhttps://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-secretsmanager/lib/secret.ts#L655
Additional Information/Context
No response
CDK CLI Version
2.118.0 (build a40f2ec)
Framework Version
No response
Node.js Version
v18.20.2
OS
MacOS Sonoma 14.5 (23F79)
Language
TypeScript
Language Version
5.4.5
Other information
No response
The text was updated successfully, but these errors were encountered: