Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
robotrapta committed Jan 20, 2025
1 parent a9cdd0a commit 8439e93
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cicd/pulumi/sweep-destroy-eeut-stacks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ destroy_stack() {
# we'll try again next cron time.
STACK_NAME=$1
pulumi stack select $STACK_NAME
# Note pulumi is too stupid to terminate an instance in the stopped state.
# So we have to do this manually.
INSTANCE_ID=$(pulumi stack output eeut_instance_id)
INSTANCE_STATE=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[*].Instances[*].State.Name' --output text)
if [ "$INSTANCE_STATE" == "stopped" ]; then
echo "Instance $INSTANCE_ID is stopped. Terminating..."
aws ec2 terminate-instances --instance-ids $INSTANCE_ID || echo "Failed to terminate instance $INSTANCE_ID"
INSTANCE_ID=$(pulumi stack output eeut_instance_id 2>/dev/null)
if [ -n "$INSTANCE_ID" ]; then
# Note pulumi is too stupid to terminate an instance in the stopped state.
# So we check for this manually.
INSTANCE_STATE=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[*].Instances[*].State.Name' --output text)
if [ "$INSTANCE_STATE" == "stopped" ]; then
echo "Instance $INSTANCE_ID is stopped. Terminating..."
aws ec2 terminate-instances --instance-ids $INSTANCE_ID || echo "Failed to terminate instance $INSTANCE_ID"
fi
fi
pulumi destroy --yes || echo "Failed to destroy stack $STACK_NAME"
pulumi stack rm $STACK_NAME --yes || echo "Failed to remove stack $STACK_NAME"
Expand Down

0 comments on commit 8439e93

Please sign in to comment.