diff --git a/scripts/awsvpcscleanup.sh b/scripts/awsvpcscleanup.sh index f3250355..6c340d1c 100755 --- a/scripts/awsvpcscleanup.sh +++ b/scripts/awsvpcscleanup.sh @@ -47,6 +47,15 @@ route_tables=$(aws ec2 describe-route-tables \ --output text | tr -d '\r' | tr '\n' ' ') for rt in $route_tables; do echo "Deleting route table: $rt" + # Check if this is the main route table + is_main=$(aws ec2 describe-route-tables \ + --route-table-ids "$rt" \ + --query "RouteTables[0].Associations[?Main==true]" \ + --output text | tr -d '\r' | tr '\n' ' ') + if [ -n "$is_main" ]; then + echo "Skipping main route table: $rt" + continue + fi associations=$(aws ec2 describe-route-tables \ --route-table-ids "$rt" \ --query "RouteTables[0].Associations[].RouteTableAssociationId" \