generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Open
go-to-k
wants to merge
25
commits into
aws:main
Choose a base branch
from
go-to-k:destroy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+371
−9
Conversation
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
test titles test tiltes modify tests allTopLevel in tests modify tests rm test add test title
auto-merge was automatically disabled
December 10, 2025 12:18
Head branch was pushed to by a user without write access
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #984 +/- ##
==========================================
+ Coverage 87.38% 87.72% +0.34%
==========================================
Files 71 72 +1
Lines 10010 10084 +74
Branches 1311 1341 +30
==========================================
+ Hits 8747 8846 +99
+ Misses 1240 1214 -26
- Partials 23 24 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
integ integ integ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes aws/aws-cdk#32836, aws/aws-cdk#32545, aws/aws-cdk#27179, aws/aws-cdk#22240
Reason for this change
This PR implements the feature that warns users when non-existent stacks are specified in
cdk destroy.Are you sure you want to delete:if there is no matching stack.cdk destroywill not fail, it will just print a warning.For examples (that have
Stacka,StackA,StackX):Difference from previous PR
The previous PR was reverted in aws/aws-cdk#32839 due to a regression with only nested stage stacks. So this version addresses that regression with comprehensive tests.
Description of changes
The original implementation added warnings for non-existent stacks in
cdk destroy, but it failed when applications had only nested stage stacks (no top-level stacks). This happened because the code usedallTopLevel: true, which only searched for stacks directly under the App, ignoring stacks within nested Stages.Fixed the regression by changing
suggestStacksmethod to useDefaultSelection.AllStacksinstead ofallTopLevel: true, ensuring the warning feature works for all stack configurations (top-level only, nested only, or both). Added regression tests to verify the fix for the nested stage scenario.private async suggestStacks(props: { selector: StackSelector; stacks: StackCollection; exclusively?: boolean; }) { const assembly = await this.assembly(); const selectorWithoutPatterns: StackSelector = { - ...props.selector, - allTopLevel: true, patterns: [], }; const stacksWithoutPatterns = await assembly.selectStacks(selectorWithoutPatterns, { extend: props.exclusively ? ExtendedStackSelection.None : ExtendedStackSelection.Downstream, - defaultBehavior: DefaultSelection.OnlySingle, + defaultBehavior: DefaultSelection.AllStacks, });Additional Information
When running
cdk destroy --allorcdk deploy --allagainst a configuration with no top-level stacks (nested stages only), the following error occurs.However, this behavior existed before this PR and is unrelated to the changes made here. Since it is outside the scope of this PR, no fix has been implemented for this behavior.
P.S.
I have submitted a PR about this behavior, but I will close the PR if it meets the specifications. Otherwise, the above implementation with
defaultBehavior: DefaultSelection.AllStacksinstead ofallTopLevel: truewould not be needed.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license