-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(core): add setter for termination protection #14463
Comments
Not sure if this will solve your problem, but have you considered creating an aspect that loops over your stacks and sets termination protection over them? e.g. export class DisableTerminationProtectionAspect implements IAspect {
visit(construct: IConstruct): void {
if (Stack.isStack(construct)) {
(<any>construct).terminationProtection = false;
}
}
} And then add the aspect to all your stacks which you are defining: for (const stack of listOfStacks) {
Aspects.of(stack).add(new DisableTerminationProtectionAspect());
} |
@jashgala That’s what we want to do, but it won’t work right now because the terminationProtection field is read-only, hence this request. |
I tried testing this behavior locally and here's a easy to re-produce example: import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
import { Aspects, IAspect, IConstruct, Stack } from '@aws-cdk/core';
export class DisableTerminationProtectionAspect implements IAspect {
visit(construct: IConstruct): void {
if (Stack.isStack(construct)) {
(<any>construct).terminationProtection = false;
}
}
}
export class CdkPlaygroundStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const bucket = new s3.Bucket(this, 'Bucket');
}
}
const app = new cdk.App();
const stack1 =new CdkPlaygroundStack(app, 'CdkPlaygroundStack1', {
env: {
account: process.env.ACCOUNT_ID,
region: process.env.REGION,
},
terminationProtection: true
});
const stack2 = new CdkPlaygroundStack(app, 'CdkPlaygroundStack2', {
env: {
account: process.env.ACCOUNT_ID,
region: process.env.REGION,
},
terminationProtection: true
});
Aspects.of(stack1).add(new DisableTerminationProtectionAspect());
Aspects.of(stack2).add(new DisableTerminationProtectionAspect()); When I deployed the above without the last two lines, the stacks deployed with termination protection enabled. However, after adding the last two lines and re-deploying, the stacks have their termination protection disabled. Somehow the aspect is working fine without needing a separate setter. |
Then it sounds like there is a bug in CDK allowing you to set purportedly read-only fields. For example, the Java documentation does not have a setter. https://docs.aws.amazon.com/cdk/api/latest/java/index.html?software/amazon/awscdk/core/Stack.html Neither does the C# documentation. https://docs.aws.amazon.com/cdk/api/latest/dotnet/api/Amazon.CDK.Stack.html#Amazon_CDK_Stack_TerminationProtection Even the TypeScript code claims it is read-only. aws-cdk/packages/@aws-cdk/core/lib/stack.ts Lines 132 to 137 in 283ed02
|
This commit adds a getter and setter for Stack termination protection. This allows termination protection to be configured after the Stack has been constructed. fixes aws#14463
ping @rix0rrr |
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Do not close. |
@rittneje Can I take this? |
Go for it. |
|
Please add a setter for the termination protection flag to the
Stack
class. https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Stack.html#terminationprotectionUse Case
We would like to be able to automatically enable termination protection to all of our stacks via an
Aspect
. However, since there is no setter for this property (it can only be set in the constructor), there's no way for that to work.This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: