Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,9 @@ export class Toolkit extends CloudAssemblySourceBuilder {
stackExisted: result.stackArn !== undefined,
});

await ioHelper.notify(IO.CDK_TOOLKIT_I7900.msg(chalk.green(`\n✅ ${chalk.blue(stack.displayName)}: ${action}ed`), stack));
// `destroyStack` returns no ARN when CloudFormation has no such stack: nothing was deleted
const outcome = result.stackArn === undefined ? 'not deployed, nothing to destroy' : `${action}ed`;
await ioHelper.notify(IO.CDK_TOOLKIT_I7900.msg(chalk.green(`\n✅ ${chalk.blue(stack.displayName)}: ${outcome}`), stack));

if (options.express) {
const warning = formatExpressStabilizationWarning(result.stabilizingResources, 'destroy');
Expand Down
26 changes: 25 additions & 1 deletion packages/@aws-cdk/toolkit-lib/test/actions/destroy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ beforeEach(() => {
ioHost.requestSpy.mockClear();
jest.clearAllMocks();

mockDestroyStack = jest.spyOn(deployments.Deployments.prototype, 'destroyStack').mockResolvedValue({ stabilizingResources: [] });
mockDestroyStack = jest.spyOn(deployments.Deployments.prototype, 'destroyStack').mockResolvedValue({
stackArn: 'arn:aws:cloudformation:region:account:stack/test-stack',
stabilizingResources: [],
});
});

describe('destroy', () => {
Expand All @@ -44,6 +47,27 @@ describe('destroy', () => {
}));
});

test('reports a stack that is not deployed instead of claiming it was destroyed', async () => {
// GIVEN: CloudFormation has no such stack, so destroyStack returns no ARN
mockDestroyStack.mockResolvedValue({ stabilizingResources: [] });

// WHEN
const cx = await builderFixture(toolkit, 'stack-with-role');
await toolkit.destroy(cx, { stacks: { strategy: StackSelectionStrategy.ALL_STACKS } });

// THEN
expect(ioHost.notifySpy).toHaveBeenCalledWith(expect.objectContaining({
action: 'destroy',
level: 'result',
code: 'CDK_TOOLKIT_I7900',
message: expect.stringContaining('not deployed, nothing to destroy'),
}));
expect(ioHost.notifySpy).not.toHaveBeenCalledWith(expect.objectContaining({
code: 'CDK_TOOLKIT_I7900',
message: expect.stringContaining(': destroyed'),
}));
});

test('multiple stacks', async () => {
// WHEN
const cx = await builderFixture(toolkit, 'two-empty-stacks');
Expand Down
Loading