feat(cli): warn of non-existent stacks in cdk destroy - #984
Merged
Conversation
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 12:10 — with
GitHub Actions
Failure
aws-cdk-automation
enabled auto-merge
December 10, 2025 12:10
auto-merge was automatically disabled
December 10, 2025 12:18
Head branch was pushed to by a user without write access
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 12:18 — with
GitHub Actions
Failure
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 12:28 — with
GitHub Actions
Failure
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #984 +/- ##
==========================================
- Coverage 91.38% 91.34% -0.04%
==========================================
Files 80 80
Lines 12264 12264
Branches 1747 1745 -2
==========================================
- Hits 11207 11203 -4
- Misses 1021 1025 +4
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 13:08 — with
GitHub Actions
Failure
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 13:13 — with
GitHub Actions
Failure
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 13:17 — with
GitHub Actions
Failure
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 14:13 — with
GitHub Actions
Failure
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 14:15 — with
GitHub Actions
Failure
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 14:16 — with
GitHub Actions
Failure
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 14:18 — with
GitHub Actions
Failure
go-to-k
had a problem deploying
to
integ-approval
December 10, 2025 14:31 — with
GitHub Actions
Failure
The `refactor` command only operates on the stacks that are relevant for the target CDK application. However, it gets all the templates of the deployed stacks before filtering them, which is wasteful. Invert the order, so that the filtering happens before getting the templates. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
Contributor
|
@go-to-k I am looking to get this in soon (hence the rebase), but first want to change |
mrgrain
approved these changes
Aug 24, 2026
Contributor
|
|
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
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.
FYI: I have submitted an issue and a PR about this behavior.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license