Skip to content

Commit 0ebfd07

Browse files
author
naman-msft
committed
added a cleanup script to run in Ross dev account daily to prevent costs from piling up
1 parent a5c316b commit 0ebfd07

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

0 commit comments

Comments
 (0)