Open hoegertn opened 11 months ago
@TheRealAmazonKendra as discussed in Las Vegas
Love it! Thank you for the feature request!
related to https://github.com/aws/aws-cdk/issues/28183
I love this idea!
When a user sets the deletion policy of a resource manually, it overrides the default deletion policy set for the ephemeral Stack.
I agree, but I have one concern.
Some resources have default RemovalPolicy set to SNAPSHOT
.
https://github.com/aws/aws-cdk/blob/665396fa8485ab642c27acf30df85f2b023acde4/packages/aws-cdk-lib/aws-rds/lib/cluster.ts#L1110
In this case, it may be difficult for Aspects( or something) to determine whether the user wants to explicitly set it to SNAPSHOT
in the ephemeral stack (DeleteAll) or whether it should be set to DESTROY
since the user has not overridden it manually.
Also, in the case of DeleteAll, it would be more convenient for me personally if an option like emptyOnDelete
could be enabled!
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html#autodeleteobjects
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr.Repository.html#emptyondelete
I fully agree. That is why I propose this a a top-level feature and not as an aspect. Each L2/L3 should be able to decide what happens on ephemeral stacks and not the author of the aspect.
Describe the feature
Currently, the AWS CDK does not provide a built-in way to configure a Stack as ephemeral. This proposal suggests adding a stack property to the Stack class that allows users to mark a Stack as ephemeral. When a Stack is marked as ephemeral, its deletion policy and the one of all resources created within should be set to Delete by default, instead of the default Retain. This will ensure that when an ephemeral Stack is deleted, all associated resources are also deleted automatically.
Use Case
The ability to create ephemeral Stacks would be beneficial for various scenarios, such as test deployments, feature branches, and integration testing. By marking a Stack as ephemeral, users can easily create instances of their CDK stack for temporary purposes without worrying about manual cleanup. This can greatly improve development workflows and enable faster iteration for developers.
Proposed Solution
To make the configuration of ephemeral Stacks future-proof and allow for variants between deleting everything and retaining everything, it is proposed to add an enumeration property to the Stack class in the AWS CDK. This enumeration property can have different values to specify the desired deletion behavior, such as "DeleteAll" for deleting all resources, "RetainAll" for retaining all resources, and potentially additional options for different deletion policies. By using an enumeration, users can easily configure the desired behavior while providing flexibility for future variants if needed.
When a user sets the deletion policy of a resource manually, it overrides the default deletion policy set for the ephemeral Stack. If a resource's deletion policy is manually set to "Retain", for example, it will not be automatically deleted when the ephemeral Stack is deleted. This can lead to unintended consequences, as the resource may continue to exist and potentially accrue costs even after the ephemeral Stack is deleted. It is important for users to be aware of this and exercise caution when manually setting deletion policies for resources within an ephemeral Stack.
Other Information
Warning
To prevent users from accidentally creating unsafe deployments, it is important to add a warning when using the ephemeral Stack property. The warning should remind users that ephemeral Stacks are meant for temporary use and should not be used for long-term or critical deployments. This will help users make informed decisions and avoid unintended consequences.
Please feel free to provide detailed feedback and comments on this proposal. Your input is highly valued and will play a crucial role in shaping the final outcome. I would greatly appreciate any specific suggestions, concerns, or ideas you may have regarding this proposal. Your perspective and expertise are important in ensuring that this proposal meets all necessary requirements and addresses all relevant aspects. Thank you in advance for taking the time to review and provide your input.
I am willing to implement this proposal and/or create a pull request if it is found useful. Depending on the current process I am also open to creating an RFC for this in the correct place.
Acknowledgements
CDK version used
2.x
Environment details (OS name and version, etc.)
all