-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
feat(core): RemovalPolicies.of(scope)
#32283
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #32283 +/- ##
==========================================
+ Coverage 82.24% 82.37% +0.13%
==========================================
Files 119 120 +1
Lines 6875 6933 +58
Branches 1161 1169 +8
==========================================
+ Hits 5654 5711 +57
- Misses 1118 1119 +1
Partials 103 103
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
RemovalPolicys.of(scope)
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only seen halfway through, but I'll leave you with my comments so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @watany-dev thanks for continuing to iterate with me on this PR. sorry for the additional comments -- i want to make sure that this one is right before we send it out. my main thing is that removalPolicyAspect
shouldn't be a property anymore, now that you've added MissingRemovalPolicies
class. Please let me know if you have any questions, i'll continue to monitor this PR. Thanks!
/** | ||
* Whether to respect the removal policy that was previously applied to the resource. | ||
* | ||
* If set to `true`, the removal policy will only be applied if the resource | ||
* doesn't already have a removal policy set. | ||
* | ||
* @default false | ||
*/ | ||
readonly respectPreviousPolicy?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would expect this property to be deleted, now that the classes we expose determine this behavior. what would it mean to have a MissingRemovalPolicy.apply(..., { respectPreviousPolicy: false })
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my carelessness. I hope you are cured.
*/ | ||
class RemovalPolicyAspect extends BaseRemovalPolicyAspect { | ||
protected shouldApplyPolicy(cfnResource: CfnResource): boolean { | ||
// If respectPreviousPolicy is true, only apply if no policy exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was hoping respectPreviousPolicy
was no longer a property set by the user. RemovalPolicyAspect
should always apply the policy (i.e. it's as if respectPreviousPolicy
was false). MissingRemovalPolicyAspect
behaves as if respectPreviousPolicy
was true.
that way, the user doesn't have to set respectPreviousPolicy
and rahter just decides either to use RemovalPolicy
or MissingRemovalPolicy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry! Unnecessary properties have disappeared! I may need to consult on this, but if priority is used in the removalPolicies
to be overwritten, I'll issue a warning, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, approving @watany-dev! hopefully i didn't break the build with my changes but if i did i'll circle back and fix
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
N/A - New feature proposal
Reason for this change
Currently, applying removal policies to multiple resources requires setting them individually or using Tags as a workaround. This change introduces a new RemovalPolicies module that provides a more intuitive and type-safe way to manage removal policies across multiple resources, similar to the existing Tags API.
Description of changes
Added a new RemovalPolicies module that provides:
A similar interface to Tags.of() for managing removal policies
Type-safe resource type specifications using CloudFormation resource type strings
Ability to include or exclude specific resource types
Convenient methods for common removal policies (destroy, retain, snapshot, retainOnUpdateOrDelete)
Example usage:
Description of how you validated changes
TBD
Checklist
[x] My code adheres to the CONTRIBUTING GUIDE and DESIGN GUIDELINES
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license