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): set (default) stack termination protection on (parent) stage level #33239

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
test: termination protection setting in stage
  • Loading branch information
aripalo committed Jan 30, 2025
commit e7292ffec7022ae6a3f2e4c01cd472ba04de9b13
58 changes: 58 additions & 0 deletions packages/aws-cdk-lib/core/test/stage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,64 @@ describe('stage', () => {
});
});

test('Stack inherits termination protection from Stage', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please move these to the describe('stage') section?

// GIVEN
const app = new App();
const stage = new Stage(app, 'Stage', {
terminationProtection: true,
});

// WHEN
const stack1 = new Stack(stage, 'Stack1');

// THEN
expect(stack1.terminationProtection).toEqual(true);
});

test('Stack can override termination protection from Stage', () => {
// GIVEN
const app = new App();
const stage = new Stage(app, 'Stage', {
terminationProtection: true,
});

// WHEN
const stack1 = new Stack(stage, 'Stack1', { terminationProtection: false });

// THEN
expect(stack1.terminationProtection).toEqual(false);
});

test('termination protection is inherited deeply', () => {
// GIVEN
const app = new App();
const outer = new Stage(app, 'Stage', {
terminationProtection: true,
});

// WHEN
const inner = new Stage(outer, 'Acct');

// THEN
expect(inner.terminationProtection).toEqual(true);
expect(new Stack(inner, 'Stack').terminationProtection).toEqual(true);
});

test('termination protection can be overridden in inner stage', () => {
// GIVEN
const app = new App();
const outer = new Stage(app, 'Stage', {
terminationProtection: false,
});

// WHEN
const inner = new Stage(outer, 'Acct', { terminationProtection: true });

// THEN
expect(inner.terminationProtection).toEqual(true);
expect(new Stack(inner, 'Stack').terminationProtection).toEqual(true);
});

test('missing context in Stages is propagated up to root assembly', () => {
// GIVEN
const app = new App();
Expand Down