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 <shivaku@nvidia.com>
  • Loading branch information
shivakunv committed Dec 17, 2024
1 parent 0c9873b commit 094b980
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/awscleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ''
Expand Down

0 comments on commit 094b980

Please sign in to comment.