diff --git a/scripts/awsvpcscleanup.sh b/scripts/awsvpcscleanup.sh index 4dd03e81..27a2e2b2 100755 --- a/scripts/awsvpcscleanup.sh +++ b/scripts/awsvpcscleanup.sh @@ -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