Skip to content

Daily RG Cleanup

Daily RG Cleanup #1

name: Daily RG Cleanup
on:
# schedule:
# # runs every day at 02:00 UTC
# - cron: '0 2 * * *'
workflow_dispatch:
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: 'Az CLI login'
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Cleanup Resource Groups
run: |
substrings=(
"myVMResourceGroup" "myLEMPResourceGroup" "myAKSResourceGroup"
"myResourceGroup" "dasha" "rg-" "myVMSSResourceGroup" "LinuxRG"
"LLMResourceGroup" "MC_" "myPostgresResourceGroup" "MyResourceGroup"
"myStaticWebAppResourceGroup" "contoso" "ignite" "SpringBoot"
"SpeechAppGroup" "MC_"
)
# fetch once
rgs=$(az group list --output json)
for sub in "${substrings[@]}"; do
echo "Looking for RGs containing '$sub'…"
echo "$rgs" |
jq -r --arg s "$sub" '.[] | select(.name | contains($s)) | .name' |
while read -r rg; do
echo "Deleting $rg"
az group delete --name "$rg" --yes --no-wait
done
done