Skip to content

Commit

Permalink
feat(mixins): implemented skip deletion for cleanupStacks and updated…
Browse files Browse the repository at this point in the history
… runtime
  • Loading branch information
OrdonioSa committed Apr 2, 2024
1 parent 30bc29e commit b017af0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/mixins/CleanupStacks.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import { CodePipelineMixin } from './Mixin';
export class CleanupStacksMixin extends CodePipelineMixin {

private readonly qualifier: string;
private readonly skipDeletion: string;

constructor(cdkQualifier: string = DefaultStackSynthesizer.DEFAULT_QUALIFIER) {
constructor(props?: { cdkQualifier?: string; skipDeletion?: 'true'|'false' }) {
super();
this.qualifier = cdkQualifier;
this.qualifier = props?.cdkQualifier ?? DefaultStackSynthesizer.DEFAULT_QUALIFIER;
this.skipDeletion = props?.skipDeletion ?? 'false';
}

preDoBuildPipeline(_codePipeline: CodePipeline) {
Expand All @@ -33,6 +35,7 @@ export class CleanupStacksMixin extends CodePipelineMixin {
const cleanupFunction = new CleanupStacksFunction(stack, 'CleanupStacks', {
environment: {
CDK_QUALIFIER: this.qualifier,
SKIP_DELETION: this.skipDeletion,
},
});
cleanupFunction.addToRolePolicy(new PolicyStatement({
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/functions/CleanupStacks-function.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/mixins/functions/CleanupStacks.lambda.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const onUpdate = async (event: any) => {
return { PhysicalResourceId: event.PhysicalResourceId };
};
const onDelete = async (event: any) => {
if (process.env.SKIP_DELETION && process.env.SKIP_DELETION == 'true') {
console.log('Skipping Deletion.');
return { PhysicalResourceId: event.PhysicalResourceId };
}
console.log('Delete');
const { stackName, account, region } = event.ResourceProperties;
const credentials = await getDeploymentAccountCredentials(account, region);
Expand Down

0 comments on commit b017af0

Please sign in to comment.