Skip to content

Commit

Permalink
only delete stack in failed status. added unit test for updating roll…
Browse files Browse the repository at this point in the history
…back_in_progress
  • Loading branch information
shivlaks committed Jul 7, 2020
1 parent 0eb752e commit 5b67fa9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export async function deployStack(options: DeployStackOptions): Promise<DeploySt
const deployName = options.deployName || stackArtifact.stackName;
let cloudFormationStack = await CloudFormationStack.lookup(cfn, deployName);

if (cloudFormationStack.stackStatus.isCreationFailure) {
if (cloudFormationStack.stackStatus.isFailure) {
debug(`Found existing stack ${deployName} that had previously failed creation. Deleting it before attempting to re-create it.`);
await cfn.deleteStack({ StackName: deployName }).promise();
const deletedStack = await waitForStack(cfn, deployName, false);
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk/test/api/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ test('even if the bootstrap stack failed to create, can still retry bootstrappin
// (first is for version checking, second is in deploy-stack.ts)
.mockImplementationOnce(() => ({ Stacks: [
{
StackStatus: 'ROLLBACK_COMPLETE',
StackStatus: 'ROLLBACK_FAILED',
StackStatusReason: 'It is magic',
Outputs: [
{ OutputKey: 'BucketName', OutputValue: 'bucket' },
Expand All @@ -225,7 +225,7 @@ test('even if the bootstrap stack failed to create, can still retry bootstrappin
] }))
.mockImplementationOnce(() => ({ Stacks: [
{
StackStatus: 'ROLLBACK_COMPLETE',
StackStatus: 'ROLLBACK_FAILED',
StackStatusReason: 'It is magic',
Outputs: [
{ OutputKey: 'BucketName', OutputValue: 'bucket' },
Expand Down
31 changes: 27 additions & 4 deletions packages/aws-cdk/test/api/deploy-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ test('deploy is not skipped if parameters are different', async () => {
}));
});

test('if existing stack failed to create, it is deleted and recreated', async () => {
test('if existing stack failed, it is deleted and recreated', async () => {
// GIVEN
givenStackExists(
{ StackStatus: 'ROLLBACK_COMPLETE' }, // This is for the initial check
{ StackStatus: 'ROLLBACK_FAILED' }, // This is for the initial check
{ StackStatus: 'DELETE_COMPLETE' }, // Poll the successful deletion
{ StackStatus: 'CREATE_COMPLETE' }, // Poll the recreation
);
Expand All @@ -275,10 +275,10 @@ test('if existing stack failed to create, it is deleted and recreated', async ()
}));
});

test('if existing stack failed to create, it is deleted and recreated even if the template did not change', async () => {
test('if existing stack is in a failed state, it is deleted and recreated even if the template did not change', async () => {
// GIVEN
givenStackExists(
{ StackStatus: 'ROLLBACK_COMPLETE' }, // This is for the initial check
{ StackStatus: 'ROLLBACK_FAILED' }, // This is for the initial check
{ StackStatus: 'DELETE_COMPLETE' }, // Poll the successful deletion
{ StackStatus: 'CREATE_COMPLETE' }, // Poll the recreation
);
Expand All @@ -298,6 +298,29 @@ test('if existing stack failed to create, it is deleted and recreated even if th
}));
});

test('stack in ROLLBACK_COMPLETE state can be updated', async () => {
// GIVEN
givenStackExists(
{ StackStatus: 'ROLLBACK_COMPLETE' }, // This is for the initial check
{ StackStatus: 'UPDATE_COMPLETE' }, // Poll the successful update
);
givenTemplateIs({ changed: 123 });

// WHEN
await deployStack({
stack: FAKE_STACK,
sdk,
sdkProvider,
resolvedEnvironment: mockResolvedEnvironment(),
});

// THEN
expect(cfnMocks.deleteStack).not.toHaveBeenCalled();
expect(cfnMocks.createChangeSet).toHaveBeenCalledWith(expect.objectContaining({
ChangeSetType: 'UPDATE',
}));
});

test('deploy not skipped if template did not change and --force is applied', async () => {
// GIVEN
givenStackExists();
Expand Down

0 comments on commit 5b67fa9

Please sign in to comment.