Skip to content

Commit

Permalink
chore: update error-destroy to remove nat gateways and lbs
Browse files Browse the repository at this point in the history
  • Loading branch information
fidiego committed Nov 19, 2024
1 parent b34f85c commit bf2e448
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions error-destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit bf2e448

Please sign in to comment.