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

CDK RemovalPolicy maps to Pulumi retainOnDelete #223

Merged
merged 5 commits into from
Nov 18, 2024

Conversation

corymhall
Copy link
Contributor

This PR maps CloudFormation DeletionPolicy
to Pulumi retainOnDelete.

DeletionPolicy => retainOnDelete

  • Delete => false
  • Retain => true
  • RetainExceptOnCreate => true
  • Snapshot => true

Looking specifically for validation on Snapshot mapping. This
functionality does not exist in Pulumi so I decided to err on the side
of caution and retain the resource instead of deleting it. We log a
warning in this case and they should see the retention in the preview.

closes #188

This PR maps CloudFormation [DeletionPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html)
to Pulumi `retainOnDelete`.

**`DeletionPolicy` => `retainOnDelete`**

- `Delete` => `false`
- `Retain` => `true`
- `RetainExceptOnCreate` => `true`
- `Snapshot` => `true`

Looking specifically for validation on `Snapshot` mapping. This
functionality does not exist in Pulumi so I decided to err on the side
of caution and retain the resource instead of deleting it. We log a
warning in this case and they should see the retention in the preview.

closes #188
@corymhall corymhall force-pushed the corymhall/removal-policy branch from 35f621d to 6f35433 Compare November 18, 2024 17:50
@corymhall corymhall self-assigned this Nov 18, 2024
super(app, id, options);
new s3.Bucket(this, 'testbucket', {
bucketName: bucketName,
removalPolicy: RemovalPolicy.RETAIN,
Copy link
Member

Choose a reason for hiding this comment

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

Nice

case cdk.CfnDeletionPolicy.RETAIN_EXCEPT_ON_CREATE:
return true;
case cdk.CfnDeletionPolicy.SNAPSHOT:
warn(`DeletionPolicy Snapshot is not supported. Resource '${logicalId}' will be retained.`);
Copy link
Member

Choose a reason for hiding this comment

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

Nice. This is good I think.

case cdk.CfnDeletionPolicy.DELETE:
return false;
case cdk.CfnDeletionPolicy.RETAIN:
case cdk.CfnDeletionPolicy.RETAIN_EXCEPT_ON_CREATE:
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Comment from L312 can move here :) But I found it. Good.

Copy link
Member

@t0yv0 t0yv0 left a comment

Choose a reason for hiding this comment

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

This is great.🚢

We can table discussing if we want further work on this but let's maybe merge this. Much better to have this handling that none. The code itself LGTM.

@corymhall corymhall merged commit e960bb9 into main Nov 18, 2024
13 checks passed
@corymhall corymhall deleted the corymhall/removal-policy branch November 18, 2024 19:42
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v1.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support removalPolicy for stateful resources
3 participants