Skip to content

Commit 094b980

Browse files
committed
unused aws instace and vpcs cleanup
Signed-off-by: shiva kumar <[email protected]>
1 parent 0c9873b commit 094b980

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

.github/workflows/awscleanup.yaml

+17-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,24 @@ jobs:
4646
--filters "Name=tag:Name,Values=ci*" \
4747
--query "Vpcs[].VpcId" \
4848
--output text | tr -d '\r' | tr '\n' ' ')
49+
# Check if the VPC has a main route table
50+
old_vpcs=""
51+
for vpc in $vpcs; do
52+
main_route_table=$(aws ec2 describe-route-tables \
53+
--filters Name=vpc-id,Values=$vpc \
54+
--query "RouteTables[?Associations[?Main==true]].RouteTableId" \
55+
--output text)
56+
57+
if [ -z "$main_route_table" ]; then
58+
echo "No main route table found for VPC: $vpc. Skipping."
59+
continue
60+
fi
4961
50-
echo "Found VPCs: $vpcs"
51-
echo "vpcs=$vpcs" >> $GITHUB_ENV
62+
echo "VPC: $vpc is valid for processing."
63+
old_vpcs="$old_vpcs $vpc"
64+
done
65+
echo "Old VPCs: $old_vpcs"
66+
echo "vpcs=$old_vpcs" >> $GITHUB_ENV
5267
5368
- name: Terminate EC2 Instances
5469
if: env.instances != ''

0 commit comments

Comments
 (0)