Skip to content

Commit

Permalink
Merge remote-tracking branch 'iidy/x-cleanup-in-progress' into iidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazzer committed Jun 21, 2024
2 parents f3a04d2 + e4e1fe4 commit cceeb4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/cfn/getStackDescription.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { TERMINAL } from './statusTypes';

import * as _ from 'lodash';
import * as aws from 'aws-sdk'

export async function getStackDescription(StackName: string): Promise<aws.CloudFormation.Stack> {
export async function getStackDescription(StackName: string, expectTerminalStatus: boolean = false): Promise<aws.CloudFormation.Stack> {
const cfn = new aws.CloudFormation();
const stacks = await cfn.describeStacks({StackName}).promise();
const stacks = await (async () => {
if (expectTerminalStatus) {
while (!_.includes(TERMINAL, (await cfn.describeStacks({StackName}).promise()).Stacks![0].StackStatus)) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
return await cfn.describeStacks({StackName}).promise();
})();
if (_.isUndefined(stacks.Stacks) || stacks.Stacks.length < 1) {
throw new Error(`${StackName} not found. Has it been deleted? Check the AWS Console.`);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/cfn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CreateStack extends AbstractCloudFormationStackCommand {

class UpdateStack extends AbstractCloudFormationStackCommand {
cfnOperation: CfnOperation = 'UPDATE_STACK';
expectedFinalStackStatus = ['UPDATE_COMPLETE', 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS'];
expectedFinalStackStatus = ['UPDATE_COMPLETE'];

async _run() {
return this._runUpdate();
Expand Down Expand Up @@ -130,7 +130,7 @@ export class CreateChangeSet extends AbstractCloudFormationStackCommand {

class ExecuteChangeSet extends AbstractCloudFormationStackCommand {
cfnOperation: CfnOperation = 'EXECUTE_CHANGESET'
expectedFinalStackStatus = ['UPDATE_COMPLETE', 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS', 'CREATE_COMPLETE']
expectedFinalStackStatus = ['UPDATE_COMPLETE', 'CREATE_COMPLETE']

async _run() {
await this.cfn.executeChangeSet(
Expand Down
2 changes: 1 addition & 1 deletion src/cfn/summarizeStackContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function summarizeStackContents(
const resourcesPromise = cfn.describeStackResources({StackName: StackId}).promise();
const exportsPromise = getAllStackExportsWithImports(StackId);
const changeSetsPromise = cfn.listChangeSets({StackName: StackId}).promise();
const stack = await (stackPromise || getStackDescription(StackId));
const stack = await (stackPromise || getStackDescription(StackId, true));
const resources = def([], (await resourcesPromise).StackResources);
// TODO paginate resource lookup ^
if (resources.length > 0) {
Expand Down

0 comments on commit cceeb4d

Please sign in to comment.