Skip to content

Commit

Permalink
unused aws instace and vpcs cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: shiva kumar <shivaku@nvidia.com>
  • Loading branch information
shivakunv committed Dec 19, 2024
1 parent 4d05d00 commit b6dabe2
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions scripts/awscleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ instances=$(aws ec2 describe-instances \
--query "Reservations[].Instances[].InstanceId" \
--output text | tr -d '\r' | tr '\n' ' ')
for instance in $instances; do
echo "Terminating instance: $instance"
aws ec2 terminate-instances --instance-ids "$instance"
done

Expand All @@ -29,14 +28,12 @@ for sg in $security_groups; do
--query "NetworkInterfaces[].NetworkInterfaceId" \
--output text | tr -d '\r' | tr '\n' ' ')
for eni in $enis; do
echo "Terminating delete-security-group: $eni"
aws ec2 modify-network-interface-attribute \
--network-interface-id "$eni" \
--groups "$(aws ec2 describe-security-groups \
--query 'SecurityGroups[?GroupName==`default`].GroupId' \
--output text)"
done
echo "Terminating delete-security-group: $sg"
aws ec2 delete-security-group --group-id "$sg"
done

Expand All @@ -46,7 +43,6 @@ subnets=$(aws ec2 describe-subnets \
--query "Subnets[].SubnetId" \
--output text | tr -d '\r' | tr '\n' ' ')
for subnet in $subnets; do
echo "Terminating delete-subnet: $subnet"
aws ec2 delete-subnet --subnet-id "$subnet"
done

Expand All @@ -71,10 +67,9 @@ for rt in $route_tables; do
first_rt=$rt
else
aws ec2 replace-route-table-association --association-id $assoc_id --route-table-id $first_rt
echo "Terminating delete-route-table: $rt"
fi
done
aws ec2 delete-route-table --route-table-id "$rt"
aws ec2 delete-route-table --route-table-id "$rt" 2>>/dev/null
done

# Delete Internet Gateway
Expand All @@ -83,7 +78,6 @@ internet_gateways=$(aws ec2 describe-internet-gateways \
--query "InternetGateways[].InternetGatewayId" \
--output text | tr -d '\r' | tr '\n' ' ')
for igw in $internet_gateways; do
echo "Terminating delete-internet-gateway: $igw"
aws ec2 detach-internet-gateway --internet-gateway-id "$igw" --vpc-id "$vpc"
aws ec2 delete-internet-gateway --internet-gateway-id "$igw"
done
Expand All @@ -93,7 +87,6 @@ done
attempts=0
echo "All resource Deleted for VPC: $vpc , now delete vpc"
while [ $attempts -lt 3 ]; do
echo "Attempting to delete VPC: $vpc (Attempt $((attempts+1)))"
if aws ec2 delete-vpc --vpc-id $vpc; then
echo "Successfully deleted VPC: $vpc"
break
Expand Down

0 comments on commit b6dabe2

Please sign in to comment.