Skip to content
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

cdk: Destroy reports success when there is nothing to destroy #22240

Open
mcqj opened this issue Sep 26, 2022 · 4 comments
Open

cdk: Destroy reports success when there is nothing to destroy #22240

mcqj opened this issue Sep 26, 2022 · 4 comments
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p3 package/tools Related to AWS CDK Tools or CLI

Comments

@mcqj
Copy link

mcqj commented Sep 26, 2022

Describe the bug

Configure AWS profile to an account that has not been bootstrapped with cdk.
Run cdk destroy - cdk reports success.

Expected Behavior

cdk should report an error indicating that the selected stack does not exist.

Current Behavior

cdk incorrectly reports success in destroying the stack.

Reproduction Steps

Create a stack, switch accounts. execute: cdk destroy

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.43.1 (build c1ebb85)

Framework Version

No response

Node.js Version

v16.16.0

OS

MacOS Monterey

Language

Typescript

Language Version

Actually, javascript but drop down does not offer that option

Other information

No response

@mcqj mcqj added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 26, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Sep 26, 2022
@peterwoodworth
Copy link
Contributor

The CDK has a check here to see if the stack exists, and just returns without making an API call if the stack wasn't found

const currentStack = await CloudFormationStack.lookup(cfn, deployName);
if (!currentStack.exists) {
return;
}

However as you've reported, it still reports success here after the function returns without doing anything

success(`\n ✅ %s: ${action}ed`, chalk.blue(stack.displayName));

I think that there are a couple ways to address this and I'd like to hear what people think. I think it would be nice if the lookup occurred before it asks the user for confirmation on if they want to destroy the stack, however what might be an easier way to address this would be to throw an error or print a statement saying we couldn't find the stack specified instead of printing the success statement.

I'm curious if people think that this should throw an error message if the stack couldn't be found, or if there should just be a printed statement. Personally I think throwing an error message to make it as clear as possible would be most helpful.

@peterwoodworth peterwoodworth added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Sep 26, 2022
@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 5, 2023

It depends a lot on what you expect. Personally I would expect at the end of cdk destroy <STACK> for it to be the case that <STACK> doesn't exist, and that is true, so I'm happy 😄 .

At least correctly printing that we didn't do anything because we didn't need to would be a good start.

@rix0rrr rix0rrr added feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p2 and removed bug This issue is a bug. p1 labels Jan 5, 2023
@rix0rrr rix0rrr removed their assignment Jan 5, 2023
@ishon19
Copy link

ishon19 commented Apr 11, 2023

I agree, we should throw an error if the specified stack or all of the stacks are not deployed when the command is run, as there is no point destroying non-existant stacks. Can I work on this change?

@peterwoodworth
Copy link
Contributor

Go ahead @ishon19!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p3 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
6 participants