File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Daily RG Cleanup
2+
3+ on :
4+ # schedule:
5+ # # runs every day at 02:00 UTC
6+ # - cron: '0 2 * * *'
7+ workflow_dispatch :
8+
9+ jobs :
10+ cleanup :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - name : ' Az CLI login'
14+ uses : azure/login@v1
15+ with :
16+ client-id : ${{ secrets.AZURE_CLIENT_ID }}
17+ tenant-id : ${{ secrets.AZURE_TENANT_ID }}
18+ subscription-id : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
19+
20+ - name : Install jq
21+ run : sudo apt-get update && sudo apt-get install -y jq
22+
23+ - name : Cleanup Resource Groups
24+ run : |
25+ substrings=(
26+ "myVMResourceGroup" "myLEMPResourceGroup" "myAKSResourceGroup"
27+ "myResourceGroup" "dasha" "rg-" "myVMSSResourceGroup" "LinuxRG"
28+ "LLMResourceGroup" "MC_" "myPostgresResourceGroup" "MyResourceGroup"
29+ "myStaticWebAppResourceGroup" "contoso" "ignite" "SpringBoot"
30+ "SpeechAppGroup" "MC_"
31+ )
32+ # fetch once
33+ rgs=$(az group list --output json)
34+
35+ for sub in "${substrings[@]}"; do
36+ echo "Looking for RGs containing '$sub'…"
37+ echo "$rgs" |
38+ jq -r --arg s "$sub" '.[] | select(.name | contains($s)) | .name' |
39+ while read -r rg; do
40+ echo "Deleting $rg"
41+ az group delete --name "$rg" --yes --no-wait
42+ done
43+ done
You can’t perform that action at this time.
0 commit comments