From d645d54852b95ae32d2d3dcf0505cfc56d9abe61 Mon Sep 17 00:00:00 2001 From: Ari Palo Date: Sun, 15 Sep 2024 17:24:10 +0000 Subject: [PATCH 1/6] feat: allow setting terminationProtection via Stage --- packages/aws-cdk-lib/core/lib/stack.ts | 8 ++- packages/aws-cdk-lib/core/lib/stage.ts | 13 +++++ packages/aws-cdk-lib/core/test/stack.test.ts | 26 +++++++++ packages/aws-cdk-lib/core/test/stage.test.ts | 58 ++++++++++++++++++++ 4 files changed, 103 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/core/lib/stack.ts b/packages/aws-cdk-lib/core/lib/stack.ts index ce3cb9c9b9fd8..c845e5e78174b 100644 --- a/packages/aws-cdk-lib/core/lib/stack.ts +++ b/packages/aws-cdk-lib/core/lib/stack.ts @@ -147,7 +147,8 @@ export interface StackProps { /** * Whether to enable termination protection for this stack. * - * @default false + * @default - The termination protection of the containing + * `Stage` if available, otherwise `false`. */ readonly terminationProtection?: boolean; @@ -434,7 +435,10 @@ export class Stack extends Construct implements ITaggable { this.account = account; this.region = region; this.environment = environment; - this._terminationProtection = props.terminationProtection ?? false; + + const parentStage = Stage.of(this); + + this._terminationProtection = props.terminationProtection ?? parentStage?.terminationProtection ?? false; if (props.description !== undefined) { // Max length 1024 bytes diff --git a/packages/aws-cdk-lib/core/lib/stage.ts b/packages/aws-cdk-lib/core/lib/stage.ts index f48ff158b9b54..7dca92dc30451 100644 --- a/packages/aws-cdk-lib/core/lib/stage.ts +++ b/packages/aws-cdk-lib/core/lib/stage.ts @@ -43,6 +43,13 @@ export interface StageProps { */ readonly env?: Environment; + /** + * Whether to enable termination protection for stacks in this stage. + * + * @default - The termination protection should be configured on the `Stack`s. + */ + readonly terminationProtection?: boolean; + /** * The output directory into which to emit synthesized artifacts. * @@ -121,6 +128,11 @@ export class Stage extends Construct { */ public readonly account?: string; + /** + * The default termination protection setting for all stacks in this stage. + */ + public readonly terminationProtection?: boolean; + /** * The cloud assembly builder that is being used for this App * @@ -167,6 +179,7 @@ export class Stage extends Construct { this.region = props.env?.region ?? this.parentStage?.region; this.account = props.env?.account ?? this.parentStage?.account; + this.terminationProtection = props.terminationProtection ?? this.parentStage?.terminationProtection; props.permissionsBoundary?._bind(this); diff --git a/packages/aws-cdk-lib/core/test/stack.test.ts b/packages/aws-cdk-lib/core/test/stack.test.ts index 82be67b19499b..b867822cb4629 100644 --- a/packages/aws-cdk-lib/core/test/stack.test.ts +++ b/packages/aws-cdk-lib/core/test/stack.test.ts @@ -2112,6 +2112,32 @@ describe('stack', () => { expect(artifact.terminationProtection).toEqual(false); }); + test('Set termination protection to true via parent Stage', () => { + // if the root is an app, invoke "synth" to avoid double synthesis + const app = new App(); + const stage = new Stage(app, 'Stage', { terminationProtection: true }); + const stack = new Stack(stage, 'Stack', {}); + + const assembly = app.synth(); + const artifact = assembly.getStackArtifact(stack.artifactId); + + expect(artifact.terminationProtection).toEqual(true); + }); + + test('Override parent Stage termination protection', () => { + // if the root is an app, invoke "synth" to avoid double synthesis + const app = new App(); + const stage = new Stage(app, 'Stage', { terminationProtection: true }); + const stack = new Stack(stage, 'Stack', {}); + + stack.terminationProtection = false; + + const assembly = app.synth(); + const artifact = assembly.getStackArtifact(stack.artifactId); + + expect(artifact.terminationProtection).toEqual(false); + }); + test('context can be set on a stack using a LegacySynthesizer', () => { // WHEN const stack = new Stack(undefined, undefined, { diff --git a/packages/aws-cdk-lib/core/test/stage.test.ts b/packages/aws-cdk-lib/core/test/stage.test.ts index 8b90643a6d137..21d18303f47b2 100644 --- a/packages/aws-cdk-lib/core/test/stage.test.ts +++ b/packages/aws-cdk-lib/core/test/stage.test.ts @@ -335,6 +335,64 @@ describe('stage', () => { expect(Stage.isStage(app)).toEqual(true); expect(Stage.isStage(externalStage)).toEqual(true); }); + + test('Stack inherits termination protection from Stage', () => { + // GIVEN + const app = new App(); + const stage = new Stage(app, 'Stage', { + terminationProtection: true, + }); + + // WHEN + const stack1 = new Stack(stage, 'Stack1', { env: { region: 'elsewhere' } }); + + // 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', () => { From 7d1dbe085f850e928792fc64ea6bb8856fa2a932 Mon Sep 17 00:00:00 2001 From: Ari Palo Date: Sun, 15 Sep 2024 17:38:15 +0000 Subject: [PATCH 2/6] test: add integ-test for stage defined termination protection --- .../core/test/integ.stage-termination-protection.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.ts b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.ts new file mode 100644 index 0000000000000..d1a91ccc71195 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.ts @@ -0,0 +1,12 @@ +import * as cdk from 'aws-cdk-lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +/** + * This test creates a stack and sets its termination protection via stage. + */ + +const app = new cdk.App(); +const stage = new cdk.Stage(app, 'Stage', { terminationProtection: true }); +const stack = new cdk.Stack(stage, 'Stack'); + +new IntegTest(app, 'stack', { testCases: [stack] }); From 05c4d02b9eb7169c4e00b89b454546bbe205345c Mon Sep 17 00:00:00 2001 From: Ari Palo Date: Sun, 15 Sep 2024 17:44:31 +0000 Subject: [PATCH 3/6] test: remove obsolete code --- packages/aws-cdk-lib/core/test/stage.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/core/test/stage.test.ts b/packages/aws-cdk-lib/core/test/stage.test.ts index 21d18303f47b2..b870b424548aa 100644 --- a/packages/aws-cdk-lib/core/test/stage.test.ts +++ b/packages/aws-cdk-lib/core/test/stage.test.ts @@ -344,7 +344,7 @@ describe('stage', () => { }); // WHEN - const stack1 = new Stack(stage, 'Stack1', { env: { region: 'elsewhere' } }); + const stack1 = new Stack(stage, 'Stack1'); // THEN expect(stack1.terminationProtection).toEqual(true); From 947d50cf84c2a34bee7ed94a79c8e30a1a14fc07 Mon Sep 17 00:00:00 2001 From: Ari Palo Date: Sun, 15 Sep 2024 18:27:13 +0000 Subject: [PATCH 4/6] docs: stage-level termination protection --- packages/aws-cdk-lib/core/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/aws-cdk-lib/core/README.md b/packages/aws-cdk-lib/core/README.md index 140d8920c44de..dc7335b832bed 100644 --- a/packages/aws-cdk-lib/core/README.md +++ b/packages/aws-cdk-lib/core/README.md @@ -1230,6 +1230,15 @@ const stack = new Stack(app, 'StackName', {}); stack.terminationProtection = true; ``` +You can also set termination protection via any parent stage and it will be inherit by all child stacks (unless overridden on stack level): +```ts +const stage = new Stack(app, 'StageName', { + terminationProtection: true, +}); + +const stack = new Stack(stage, 'StackName', {}); +``` + By default, termination protection is disabled. ### Description From 3bc276304c80d97edbaefb4767a83eab01cf0a05 Mon Sep 17 00:00:00 2001 From: Ari Palo Date: Sun, 15 Sep 2024 19:01:40 +0000 Subject: [PATCH 5/6] style: remove trailing spaces --- packages/aws-cdk-lib/core/lib/stack.ts | 2 +- packages/aws-cdk-lib/core/lib/stage.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/core/lib/stack.ts b/packages/aws-cdk-lib/core/lib/stack.ts index c845e5e78174b..b0dfaf83dc3d8 100644 --- a/packages/aws-cdk-lib/core/lib/stack.ts +++ b/packages/aws-cdk-lib/core/lib/stack.ts @@ -147,7 +147,7 @@ export interface StackProps { /** * Whether to enable termination protection for this stack. * - * @default - The termination protection of the containing + * @default - The termination protection of the containing * `Stage` if available, otherwise `false`. */ readonly terminationProtection?: boolean; diff --git a/packages/aws-cdk-lib/core/lib/stage.ts b/packages/aws-cdk-lib/core/lib/stage.ts index 7dca92dc30451..2239d0d5cf224 100644 --- a/packages/aws-cdk-lib/core/lib/stage.ts +++ b/packages/aws-cdk-lib/core/lib/stage.ts @@ -45,8 +45,8 @@ export interface StageProps { /** * Whether to enable termination protection for stacks in this stage. - * - * @default - The termination protection should be configured on the `Stack`s. + * + * @default - The termination protection should be configured on the `Stack`s. */ readonly terminationProtection?: boolean; From c8f054015219d4fa430bb1c7f1d9c61160932175 Mon Sep 17 00:00:00 2001 From: Ari Palo Date: Sun, 15 Sep 2024 19:35:59 +0000 Subject: [PATCH 6/6] test: update snapshot --- .../StageStackC6730065.assets.json | 19 +++ .../StageStackC6730065.template.json | 41 ++++++ .../assembly-Stage/cdk.out | 1 + .../assembly-Stage/manifest.json | 60 +++++++++ .../cdk.out | 1 + .../integ.json | 12 ++ .../manifest.json | 66 ++++++++++ ...efaultTestDeployAssert0386B0AD.assets.json | 19 +++ ...aultTestDeployAssert0386B0AD.template.json | 36 ++++++ .../tree.json | 119 ++++++++++++++++++ .../integ.stage-termination-protection.ts | 6 + 11 files changed, 380 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/StageStackC6730065.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/StageStackC6730065.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/stackDefaultTestDeployAssert0386B0AD.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/stackDefaultTestDeployAssert0386B0AD.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/tree.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/StageStackC6730065.assets.json b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/StageStackC6730065.assets.json new file mode 100644 index 0000000000000..26fda505ce4c5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/StageStackC6730065.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.24", + "files": { + "45709e4f85add051115e345a937f800070a446dd548beddc08dc27983c907f2e": { + "source": { + "path": "StageStackC6730065.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "45709e4f85add051115e345a937f800070a446dd548beddc08dc27983c907f2e.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/StageStackC6730065.template.json b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/StageStackC6730065.template.json new file mode 100644 index 0000000000000..0f6c08b9853fa --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/StageStackC6730065.template.json @@ -0,0 +1,41 @@ +{ + "Outputs": { + "StackTerminationProtection": { + "Value": "true" + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/cdk.out new file mode 100644 index 0000000000000..4efaa16f29af9 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.24"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/manifest.json new file mode 100644 index 0000000000000..959bc0cc71406 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/assembly-Stage/manifest.json @@ -0,0 +1,60 @@ +{ + "version": "36.0.24", + "artifacts": { + "StageStackC6730065.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "StageStackC6730065.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "StageStackC6730065": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "StageStackC6730065.template.json", + "terminationProtection": true, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/45709e4f85add051115e345a937f800070a446dd548beddc08dc27983c907f2e.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "StageStackC6730065.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + }, + "stackName": "Stage-Stack" + }, + "dependencies": [ + "StageStackC6730065.assets" + ], + "metadata": { + "/Stage/Stack/StackTerminationProtection": [ + { + "type": "aws:cdk:logicalId", + "data": "StackTerminationProtection" + } + ], + "/Stage/Stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/Stage/Stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "Stage/Stack" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/cdk.out new file mode 100644 index 0000000000000..4efaa16f29af9 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.24"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/integ.json new file mode 100644 index 0000000000000..2864aa7a987da --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.24", + "testCases": { + "stack/DefaultTest": { + "stacks": [ + "Stage/Stack" + ], + "assertionStack": "stack/DefaultTest/DeployAssert", + "assertionStackName": "stackDefaultTestDeployAssert0386B0AD" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/manifest.json new file mode 100644 index 0000000000000..983cfaa5735da --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/manifest.json @@ -0,0 +1,66 @@ +{ + "version": "36.0.24", + "artifacts": { + "assembly-Stage": { + "type": "cdk:cloud-assembly", + "properties": { + "directoryName": "assembly-Stage", + "displayName": "Stage" + } + }, + "stackDefaultTestDeployAssert0386B0AD.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "stackDefaultTestDeployAssert0386B0AD.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "stackDefaultTestDeployAssert0386B0AD": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "stackDefaultTestDeployAssert0386B0AD.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "stackDefaultTestDeployAssert0386B0AD.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "stackDefaultTestDeployAssert0386B0AD.assets" + ], + "metadata": { + "/stack/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/stack/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "stack/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/stackDefaultTestDeployAssert0386B0AD.assets.json b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/stackDefaultTestDeployAssert0386B0AD.assets.json new file mode 100644 index 0000000000000..30ca2377e45ae --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/stackDefaultTestDeployAssert0386B0AD.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.24", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "stackDefaultTestDeployAssert0386B0AD.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/stackDefaultTestDeployAssert0386B0AD.template.json b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/stackDefaultTestDeployAssert0386B0AD.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/stackDefaultTestDeployAssert0386B0AD.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/tree.json new file mode 100644 index 0000000000000..0e4fa579b92e4 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.js.snapshot/tree.json @@ -0,0 +1,119 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Stage": { + "id": "Stage", + "path": "Stage", + "children": { + "Stack": { + "id": "Stack", + "path": "Stage/Stack", + "children": { + "StackTerminationProtection": { + "id": "StackTerminationProtection", + "path": "Stage/Stack/StackTerminationProtection", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnOutput", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "Stage/Stack/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "Stage/Stack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stage", + "version": "0.0.0" + } + }, + "stack": { + "id": "stack", + "path": "stack", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "stack/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "stack/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "stack/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "stack/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "stack/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.ts b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.ts index d1a91ccc71195..aae4de541fed3 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/core/test/integ.stage-termination-protection.ts @@ -9,4 +9,10 @@ const app = new cdk.App(); const stage = new cdk.Stage(app, 'Stage', { terminationProtection: true }); const stack = new cdk.Stack(stage, 'Stack'); +new cdk.CfnOutput(stack, 'StackTerminationProtection', { + value: `${stack.terminationProtection}`, +}); + new IntegTest(app, 'stack', { testCases: [stack] }); + +app.synth(); \ No newline at end of file