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 <[email protected]>
  • Loading branch information
shivakunv committed Dec 17, 2024
1 parent 6d3d1c8 commit 4093d6e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions scripts/awsvpcscleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,23 @@ done

echo "All resource Deleted for VPC: $vpc , now delete vpc"

if aws ec2 delete-vpc --vpc-id "$vpc"; then
echo "Successfully deleted VPC: $vpc"
else
echo "Failed to delete VPC: $vpc"
attempts=0
# try 3 times with 5 minutes interval
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
else
attempts=$((attempts + 1))
if [ $attempts -lt 3 ]; then
echo "Failed to delete VPC: $vpc. Retrying in 5 minutes..."
sleep 300
fi
fi
done

if [ $attempts -eq 3 ]; then
echo "Failed to delete VPC: $vpc after 3 attempts. Skipping."
exit 1
fi

0 comments on commit 4093d6e

Please sign in to comment.