Skip to content

Commit 9d11db6

Browse files
author
naman-msft
committed
tested and finalized deletion script and it will run on 11:11 UTC everyday
1 parent e3acc7f commit 9d11db6

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

.github/workflows/script-cleanup.yml

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,28 @@ jobs:
2727

2828
- name: Cleanup Resource Groups
2929
run: |
30-
substrings=(
31-
"myVMResourceGroup" "myLEMPResourceGroup" "myAKSResourceGroup"
32-
"myResourceGroup" "dasha" "rg-" "myVMSSResourceGroup" "LinuxRG"
33-
"LLMResourceGroup" "MC_" "myPostgresResourceGroup" "MyResourceGroup"
34-
"myStaticWebAppResourceGroup" "contoso" "ignite" "SpringBoot"
35-
"SpeechAppGroup" "MC_"
36-
)
37-
rgs=$(az group list --output json)
30+
echo "Fetching all resource groups in the subscription..."
31+
rgs_json=$(az group list --output json)
3832
3933
# don’t exit on errors in this block
4034
set +e
4135
42-
for sub in "${substrings[@]}"; do
43-
echo "Looking for RGs containing '$sub'…"
44-
echo "$rgs" |
45-
jq -r --arg s "$sub" '.[] | select(.name | contains($s)) | .name' |
46-
while read -r rg; do
47-
echo -n "Deleting $rg… "
48-
az group delete \
49-
--name "$rg" \
50-
--yes \
51-
--no-wait \
52-
&& echo "OK" \
53-
|| echo "⚠️ Skipped (deny-assignment or other error)"
54-
done
55-
done
36+
echo "Attempting to delete all resource groups..."
37+
echo "$rgs_json" |
38+
jq -r '.[] | .name' |
39+
while read -r rg_name; do
40+
if [[ -z "$rg_name" ]]; then
41+
echo "Skipping empty resource group name."
42+
continue
43+
fi
44+
echo -n "Deleting $rg_name… "
45+
az group delete \
46+
--name "$rg_name" \
47+
--yes \
48+
--no-wait \
49+
&& echo "OK" \
50+
|| echo "⚠️ Skipped (deny-assignment or other error)"
51+
done
5652
5753
# restore “exit on error” if you need it later
5854
set -e

0 commit comments

Comments
 (0)