Skip to content

Commit

Permalink
Forces iidy to wait for a terminal state when summarizing stack contents
Browse files Browse the repository at this point in the history
For some reason, iidy is getting an in progress state when summarizing stack contents. It's possible this is just due to timing.
When we know we're going to be in a terminal state, we can just wait for a terminal status to be returned instead of accepting the in progress status.
It's not clear why this specifically happens with `UPDATE_COMPLETE_CLEANUP_IN_PROGRESS`, but it could be a special case for timing.
  • Loading branch information
Kazzer committed Jun 21, 2024
1 parent f3a04d2 commit e4e1fe4
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 e4e1fe4

Please sign in to comment.