Skip to content

Daily RG Cleanup

Daily RG Cleanup #4

name: Daily RG Cleanup
on:
schedule:
# runs every day at 11:11 UTC
- cron: '11 11 * * *'
workflow_dispatch:
permissions:
contents: write
id-token: write
issues: write
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_"
)
rgs=$(az group list --output json)
# don’t exit on errors in this block
set +e
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 -n "Deleting $rg… "
az group delete \
--name "$rg" \
--yes \
--no-wait \
&& echo "OK" \
|| echo "⚠️ Skipped (deny-assignment or other error)"
done
done
# restore “exit on error” if you need it later
set -e