-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(cli): cdk destroy does not throw error for a non-existent stack #27293
Conversation
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.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
Exemption Request: this should be covered with cli-integ tests. In my environment, the behavior was confirmed as expected. |
packages/aws-cdk/lib/cdk-toolkit.ts
Outdated
// No validation | ||
const notExistPatterns = selector.patterns.filter(p => !stacks.stackArtifacts.find(s => minimatch(s.hierarchicalId, p))); | ||
if (notExistPatterns.length > 0) { | ||
throw new Error(`Stacks not exist: ${notExistPatterns.join(', ')}`); |
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.
Can you please change the error message to be something more informative as to what does not exist and how they might be able to fix it?
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.
For example, if you specify stacks stack-A
, stack-X
, and stack-Y
in cdk destroy
, and only stack-A
exists in your app.
In this code, the error message is to be following, Stacks not exist: stack-X, stack-Y
. So you can know which of stacks do not exist.
how they might be able to fix it?
I think it is to difficult to know this. If you enter non-existent stacks, CDK does not know the way how to fix it unless it gets all the stacks and does a fuzzy search on all of them. Even if we did that, you probably wouldn't get the expected and accurate output.
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.
A tad more context here might be helpful, if we can provide it. Maybe something like Cannot run cdk destroy on stack(s) ${stacks.join(', ')}. ${notExistPatterns.join(', ')} are not deployed in account: ${account}, region: ${region}.
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.
A tad more context here might be helpful, if we can provide it. Maybe something like Cannot run cdk destroy on stack(s) ${stacks.join(', ')}. ${notExistPatterns.join(', ')} are not deployed in account: ${account}, region: ${region}.
I think the format is difficult.
This notExistPattern
handling and cdk destroy
check the non-existence stacks by looking not the AWS account but stack instance definitions in the cdk app (that is cloud-assembly).
My understanding is that cdk destroy
does not run the command by specifying an account or region, but looks at the stack list (CloudFormationStackArtifact[]
) in cloud-assembly and if each stack has a region/account, it is used; otherwise, the default region/account is used. Actually there is no --region
option in cdk destroy
.
So we can see that the stack entered does not exist in the CDK app in the first place, but we cannot know WHICH account/region it does not exist in. (We may know that "the stack does not exist in the DEFAULT or ANY region and account", but perhaps that is not the information the user wants to know.)
Then, how about the following message?:
Cannot run cdk destroy on stack(s) ${stacks.join(', ')}. ${notExistPatterns.join(', ')} not exist.
packages/aws-cdk/lib/cdk-toolkit.ts
Outdated
@@ -769,7 +770,10 @@ export class CdkToolkit { | |||
defaultBehavior: DefaultSelection.OnlySingle, | |||
}); | |||
|
|||
// No validation | |||
const notExistPatterns = selector.patterns.filter(p => !stacks.stackArtifacts.find(s => minimatch(s.hierarchicalId, p))); |
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.
Could you also add code such that we error out before it we even try deleting any stack, if at least one of the stacks provided does not exist?
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.
In the current code, if any of the stacks are not existing, none of the stacks are deleted. And the cdk occurs an error.
Is this not what you are assuming?
packages/aws-cdk/lib/cdk-toolkit.ts
Outdated
// No validation | ||
const notExistPatterns = selector.patterns.filter(p => !stacks.stackArtifacts.find(s => minimatch(s.hierarchicalId, p))); | ||
if (notExistPatterns.length > 0) { | ||
throw new Error(`Stacks not exist: ${notExistPatterns.join(', ')}`); |
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.
A tad more context here might be helpful, if we can provide it. Maybe something like Cannot run cdk destroy on stack(s) ${stacks.join(', ')}. ${notExistPatterns.join(', ')} are not deployed in account: ${account}, region: ${region}.
I would like to see this added as a failure case in the cli integ tests. Could you please add a test case there? |
I added cli integ tests and changed an error message to preliminary one for now. This is my first time doing cli integ tests, so please let me know if I am missing something. |
This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. |
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing |
Could you please review my changes and answers? |
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error. |
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing |
|
This PR for cli is to throw an error if stacks with wrong cases (=not exist) specified in
cdk destroy
.Closes #27179.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license