From bf2e448d321bb455704c5a35222709153e96e39e Mon Sep 17 00:00:00 2001 From: fidiego Date: Tue, 19 Nov 2024 14:04:45 -0600 Subject: [PATCH] chore: update error-destroy to remove nat gateways and lbs --- error-destroy.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/error-destroy.sh b/error-destroy.sh index 24a20ca..54aefe5 100755 --- a/error-destroy.sh +++ b/error-destroy.sh @@ -3,11 +3,36 @@ set -u set -o pipefail + echo "executing error-destroy script" +echo +echo ' region: '$AWS_REGION +echo ' profile: '$AWS_PROFILE +echo ' install id: '$NUON_INSTALL_ID +echo + echo "ensuring AWS is setup" aws sts get-caller-identity > /dev/null +echo "looking for NAT Gateways" +NAT_GATEWAYS=$(aws ec2 describe-nat-gateways --filter Name=tag:Name,Values=$NUON_INSTALL_ID*) +echo $NAT_GATEWAYS | jq -r '.NatGateways[].NatGatewayId' | while read -r nat_gateway_id; do + echo "deleting NAT Gateway "$nat_gateway_id + aws ec2 delete-nat-gateway --nat-gateway-id $nat_gateway_id +done + +echo "looking for Load Balancers" +NLBS=$(aws elbv2 describe-load-balancers | jq '.LoadBalancers') +echo $NLBS | jq -r '.[].LoadBalancerArn' | while read -r lb_arn; do + echo $lb_arn + tag_values=$(aws elbv2 describe-tags --resource-arn $lb_arn | jq -r '.TagDescriptions[].Tags.[].Value') + if [[ $tag_values == *"$NUON_INSTALL_ID"* ]]; then + echo "deleting load balancer "$lb_arn + aws elbv2 delete-load-balancer --load-balancer-arn $lb_arn + fi +done + echo "looking for ENIs which were orphaned by vpc-cni plugin" ENIS=$(aws ec2 \ describe-network-interfaces \