diff --git a/.github/workflows/awscleanup.yaml b/.github/workflows/awscleanup.yaml index 8ac4fb7e..7a18a59e 100644 --- a/.github/workflows/awscleanup.yaml +++ b/.github/workflows/awscleanup.yaml @@ -46,9 +46,24 @@ jobs: --filters "Name=tag:Name,Values=ci*" \ --query "Vpcs[].VpcId" \ --output text | tr -d '\r' | tr '\n' ' ') + # Check if the VPC has a main route table + old_vpcs="" + for vpc in $vpcs; do + main_route_table=$(aws ec2 describe-route-tables \ + --filters Name=vpc-id,Values=$vpc \ + --query "RouteTables[?Associations[?Main==true]].RouteTableId" \ + --output text) + + if [ -z "$main_route_table" ]; then + echo "No main route table found for VPC: $vpc. Skipping." + continue + fi - echo "Found VPCs: $vpcs" - echo "vpcs=$vpcs" >> $GITHUB_ENV + echo "VPC: $vpc is valid for processing." + old_vpcs="$old_vpcs $vpc" + done + echo "Old VPCs: $old_vpcs" + echo "vpcs=$old_vpcs" >> $GITHUB_ENV - name: Terminate EC2 Instances if: env.instances != ''