Skip to content

handle stack deletion if the stack was never deleted before #517

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 3 commits into from
Jun 4, 2025

Conversation

shvbsle
Copy link
Contributor

@shvbsle shvbsle commented Jun 4, 2025

Issue #, if available:

Description of changes:
You can only use force-deletion of a stack if the stack is in DELETE_FAILED state.

An error occurred (ValidationError) when calling the DeleteStack operation: Invalid operation on stack [arn:aws:cloudformation:u<stack-name>]. You can activate DeletionMode FORCE_DELETE_STACK in a delete stack operation only when the stack is in the DELETE_FAILED state.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Testing details:

docker run -it alpine/k8s:1.30.2 bash
5090a9d2b508:/apps# aws --version
aws-cli/1.33.18 Python/3.12.3 Linux/5.10.237-211.948.amzn2int.x86_64 botocore/1.34.136

5090a9d2b508:/apps# aws configure # setup accesskey, and secret, region
  1. Test-case 1: Stack deletion had failed:
5090a9d2b508:/apps# export NODE_ROLE_STACK_NAME=dummy_node_role_delete_stack_fail
STACK_STATUS=$(aws cloudformation describe-stacks --stack-name $NODE_ROLE_STACK_NAME --query 'Stacks[0].StackStatus' --output text || echo "STACK_NOT_FOUND")
echo $STACK_STATUS
DELETE_FAILED
5090a9d2b508:/apps# if [ "$STACK_STATUS" == "DELETE_FAILED" ]; then
    echo "Stack is in DELETE_FAILED state, using FORCE_DELETE_STACK"
    aws cloudformation delete-stack --stack-name $NODE_ROLE_STACK_NAME --deletion-mode FORCE_DELETE_STACK
else
    echo "Normal stack deletion"
    aws cloudformation delete-stack --stack-name $NODE_ROLE_STACK_NAME
fi
Stack is in DELETE_FAILED state, using FORCE_DELETE_STACK
  1. Test-case 2: Stack deletion was never initiated
export NODE_ROLE_STACK_NAME=dummy_node_role
5090a9d2b508:/apps# STACK_STATUS=$(aws cloudformation describe-stacks --stack-name $NODE_ROLE_STACK_NAME --query 'Stacks[0].StackStatus' --output text || echo "STACK_NOT_FOUND")
echo $STACK_STATUS
CREATE_COMPLETE
5090a9d2b508:/apps# if [ "$STACK_STATUS" == "DELETE_FAILED" ]; then
    echo "Stack is in DELETE_FAILED state, using FORCE_DELETE_STACK"
    aws cloudformation delete-stack --stack-name $NODE_ROLE_STACK_NAME --deletion-mode FORCE_DELETE_STACK
else
    echo "Normal stack deletion"
    aws cloudformation delete-stack --stack-name $NODE_ROLE_STACK_NAME
fi
Normal stack deletion

@shvbsle shvbsle changed the title WIP: reverted force deletion of the stack reverted force deletion of the stack Jun 4, 2025
@shvbsle shvbsle requested a review from hakuna-matatah June 4, 2025 15:58
… continue using stack delete without using --deletion-mode
@shvbsle shvbsle changed the title reverted force deletion of the stack handle stack deletion if the stack was never deleted before Jun 4, 2025
@shvbsle shvbsle merged commit 0b55f71 into awslabs:main Jun 4, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants