Skip to content
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): RemovalPolicys.of(scope) #32283

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

watany-dev
Copy link
Contributor

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 RemovalPolicys 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 RemovalPolicys module that provides:

  • A similar interface to Tags.of() for managing removal policies

  • Type-safe resource type specifications using either CloudFormation resource type strings or CDK resource classes

  • Ability to include or exclude specific resource types

  • Convenient methods for common removal policies (destroy, retain, snapshot, retainOnUpdateOrDelete)

Example usage:

// Using CloudFormation resource type strings
RemovalPolicys.of(scope).retain({
  applyToResourceTypes: ['AWS::S3::Bucket', 'AWS::DynamoDB::Table']
});

// Using CDK resource classes (type-safe)
RemovalPolicys.of(scope).retain({
  applyToResourceTypes: [CfnBucket, CfnTable]
});

// Mixed usage
RemovalPolicys.of(scope).retain({
  applyToResourceTypes: [CfnBucket, 'AWS::DynamoDB::Table']
});

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

@watany-dev watany-dev requested a review from a team as a code owner November 26, 2024 04:05
@aws-cdk-automation aws-cdk-automation requested a review from a team November 26, 2024 04:05
@github-actions github-actions bot added p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Nov 26, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a 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.

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.46%. Comparing base (0153da4) to head (70f9e43).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32283   +/-   ##
=======================================
  Coverage   77.46%   77.46%           
=======================================
  Files         105      105           
  Lines        7168     7168           
  Branches     1314     1314           
=======================================
  Hits         5553     5553           
  Misses       1433     1433           
  Partials      182      182           
Flag Coverage Δ
suite.unit 77.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 77.46% <ø> (ø)

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 70f9e43
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@watany-dev watany-dev changed the title feat(core): RemovalPolicys.of(scope) feat(core): RemovalPolicys.of(scope) Nov 26, 2024
@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ Features must contain a change to a README file.
❌ Features must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants