-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable termination protection on CloudFormation stacks
Signed-off-by: Austin Vazquez <[email protected]>
- Loading branch information
1 parent
1fce297
commit b10e884
Showing
15 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env node | ||
|
||
// Finch Infrastructure | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
import { Aspects, IAspect, Stack } from "aws-cdk-lib"; | ||
import { IConstruct } from "constructs"; | ||
|
||
/** | ||
* Enable termination protection in all stacks. | ||
*/ | ||
export class EnableTerminationProtectionOnStacks implements IAspect { | ||
visit(construct: IConstruct): void { | ||
if (Stack.isStack(construct)) { | ||
(<any>construct).terminationProtection = true; | ||
} | ||
} | ||
} | ||
|
||
export function applyTerminationProtectionOnStacks(constructs: IConstruct[]) { | ||
constructs.forEach((construct) => { | ||
Aspects.of(construct).add(new EnableTerminationProtectionOnStacks()); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Finch Infrastructure | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
import { App, Stack } from "aws-cdk-lib"; | ||
import { Bucket } from "aws-cdk-lib/aws-s3"; | ||
import { applyTerminationProtectionOnStacks } from "../../lib/aspects/stack-termination-protection"; | ||
|
||
describe('Stack termination protection aspect', () => { | ||
it('must enable termination protection when applied to a stack and synthesized', () => { | ||
const app = new App(); | ||
const stack = new Stack(app, 'FooStack'); | ||
// stack needs one resource | ||
new Bucket(stack, 'BarBucket'); | ||
|
||
applyTerminationProtectionOnStacks([stack]); | ||
app.synth(); | ||
|
||
expect(stack.terminationProtection).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters