-
Notifications
You must be signed in to change notification settings - Fork 119
feat(cli): warn of non-existent stacks in cdk destroy
#984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3d2c68c
refactor: filter stacks before getting their templates (#960)
otaviomacedo a1676c3
Merge branch 'main' of https://github.com/go-to-k/aws-cdk-cli into de…
go-to-k 6041851
refactor: route cdk destroy through toolkit-lib
go-to-k ec87712
chore: regenerate message registry and destroy IoHost snapshots
go-to-k b2ff421
test: migrate destroy tests to toolkit-lib
go-to-k 102d357
chore(toolkit-lib): fix picomatch import order (eslint import/order)
go-to-k ac99b78
fix(cli): make destroy IoHost snapshots color-independent
go-to-k 4626130
fix(toolkit-lib): keep destroy confirmation stack names blue
go-to-k d442ab3
Merge branch 'main' into destroy
go-to-k 9c1083c
chore: self mutation
github-actions[bot] 0cca283
Merge branch 'main' of https://github.com/go-to-k/aws-cdk-cli into de…
go-to-k 0747ba5
feat(toolkit-lib): destroy warns and suggests when stack names do not…
go-to-k d666187
fix(toolkit-lib): keep destroy confirmation stack names blue
go-to-k 484c5ca
test(toolkit-lib): drop redundant comment in destroy confirmation col…
go-to-k 6a96b5b
Merge branch 'main' into destroy
go-to-k 532e323
Merge branch 'main' into destroy
go-to-k 653c0e6
Merge branch 'main' into destroy
go-to-k a826116
Merge branch 'main' into destroy
go-to-k fa032d1
Merge branch 'main' into destroy
go-to-k 50c4d94
Merge branch 'main' into destroy
go-to-k b93a4b5
refactor(toolkit-lib): move destroy match suggestions into StackAssem…
go-to-k 739000f
small refactor
mrgrain 0ceda07
Merge branch 'main' into destroy
mrgrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...esting/cli-integ/tests/cli-integ-tests/destroy/cdk-destroy-nonexistent-stack.integtest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { integTest, withDefaultFixture } from '../../../lib'; | ||
|
|
||
| integTest('cdk destroy does not fail even if the stacks do not exist', withDefaultFixture(async (fixture) => { | ||
| const nonExistingStackName1 = 'non-existing-stack-1'; | ||
| const nonExistingStackName2 = 'non-existing-stack-2'; | ||
|
|
||
| await expect(fixture.cdkDestroy([nonExistingStackName1, nonExistingStackName2])).resolves.not.toThrow(); | ||
| })); | ||
|
|
||
| integTest('cdk destroy with no force option exits without prompt if the stacks do not exist', withDefaultFixture(async (fixture) => { | ||
| const nonExistingStackName1 = 'non-existing-stack-1'; | ||
| const nonExistingStackName2 = 'non-existing-stack-2'; | ||
|
|
||
| await expect(fixture.cdkDestroy([nonExistingStackName1, nonExistingStackName2], { | ||
| force: false, | ||
| })).resolves.not.toThrow(); | ||
| })); | ||
|
|
||
| integTest('cdk destroy does not fail even if the stages do not exist', withDefaultFixture(async (fixture) => { | ||
| await expect(fixture.cdkDestroy('NonExistent/*')).resolves.not.toThrow(); | ||
| })); |
28 changes: 28 additions & 0 deletions
28
...s-cdk-testing/cli-integ/tests/cli-integ-tests/destroy/cdk-destroy-stage-only.integtest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { DescribeStacksCommand } from '@aws-sdk/client-cloudformation'; | ||
| import { integTest, withDefaultFixture } from '../../../lib'; | ||
|
|
||
| integTest('cdk destroy can destroy stacks in stage-only configuration', withDefaultFixture(async (fixture) => { | ||
| const integStackSet = 'stage-only'; | ||
|
|
||
| const stageNameSuffix = 'stage'; | ||
| const specifiedStackName = `${stageNameSuffix}/*`; | ||
|
|
||
| await fixture.cdkDeploy(specifiedStackName, { | ||
| modEnv: { | ||
| INTEG_STACK_SET: integStackSet, | ||
| }, | ||
| }); | ||
|
|
||
| const stackName = `${fixture.fullStackName(stageNameSuffix)}-StackInStage`; | ||
| const stack = await fixture.aws.cloudFormation.send(new DescribeStacksCommand({ StackName: stackName })); | ||
| expect(stack.Stacks?.length ?? 0).toEqual(1); | ||
|
|
||
| await fixture.cdkDestroy(specifiedStackName, { | ||
| modEnv: { | ||
| INTEG_STACK_SET: integStackSet, | ||
| }, | ||
| }); | ||
|
|
||
| await expect(fixture.aws.cloudFormation.send(new DescribeStacksCommand({ StackName: stackName }))) | ||
| .rejects.toThrow(/does not exist/); | ||
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/@aws-cdk/toolkit-lib/test/_fixtures/stack-with-stage/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import * as core from 'aws-cdk-lib/core'; | ||
|
|
||
| /** | ||
| * An app with a top-level stack plus a stack nested inside a Stage. | ||
| * | ||
| * Hierarchical ids: `TopLevelStack` and `Stage/StackInStage`. Used to exercise | ||
| * destroy/suggestion behavior across both top-level and nested-stage stacks. | ||
| */ | ||
| export default async () => { | ||
| const app = new core.App({ autoSynth: false }); | ||
| new core.Stack(app, 'TopLevelStack'); | ||
| const stage = new core.Stage(app, 'Stage'); | ||
| new core.Stack(stage, 'StackInStage'); | ||
|
|
||
| return app.synth(); | ||
| }; |
16 changes: 16 additions & 0 deletions
16
packages/@aws-cdk/toolkit-lib/test/_fixtures/stage-only/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import * as core from 'aws-cdk-lib/core'; | ||
|
|
||
| /** | ||
| * An app whose only stack lives inside a Stage (no top-level stacks). | ||
| * | ||
| * This is the configuration that regressed the original `cdk destroy` warning | ||
| * feature: code that only looked at top-level stacks could not see (or suggest) | ||
| * stacks nested in a Stage. The stack's hierarchical id is `Stage/StackInStage`. | ||
| */ | ||
| export default async () => { | ||
| const app = new core.App({ autoSynth: false }); | ||
| const stage = new core.Stage(app, 'Stage'); | ||
| new core.Stack(stage, 'StackInStage'); | ||
|
|
||
| return app.synth(); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like said elsewhere, I think a single message will be enough but it should carry a payload of the unmatched selector and idenfified matches.