-
Notifications
You must be signed in to change notification settings - Fork 4.5k
(aws-cdk-lib): (Change terminationProtection on existing Stack instances) #21304
Description
Describe the feature
Currently, the only way to enable termination protection on a CDK Stack is in the props passed to the Stack's constructor, e.g.:
const myStack = new MyStack(app, "MyStack", {
terminationProtection: true,
// ...
});However, there is no way to set termination protection on an existing Stack instance. E.g., in the code above, if I then write myStack.terminationProtection = false, then I get the following compiler error:
Cannot assign to 'terminationProtection' because it is a read-only property.
I request that this property be writable.
Use Case
I'm trying to define an Aspect to enable termination protection on all of my production stacks, so that I don't accidentally forget to enable it in the CDK app. I was hoping to define this Aspect as follows, but instead I get the aforementioned compiler error.
export class ProdTerminationProtectionAspect implements IAspect {
constructor(private readonly isProduction: boolean) { }
public visit(construct: IConstruct): void {
if (!this.isProduction || !Stack.isStack(construct))
return;
construct.terminationProtection = this.isProduction; // ERROR
}
}Proposed Solution
No response
Other Information
Alternatively, you could take this as a feature request to add an "auto-termination-protection-enabling" Aspect to the CDK itself. 🙂
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
CDK version used
2.33.0 (build 859272d)
Environment details (OS name and version, etc.)
Debian buster (technically in a WSL devcontainer on Windows 11 Pro)