-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub_cleaner.sh
executable file
·55 lines (43 loc) · 1.21 KB
/
sub_cleaner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
set -ex
# Notes:
# functions to wipe all resources on one subscription.
# Be careful to run this script.
# show account to make sure you work on proper account
# if there are multiple accounts with same name (disabled and enabled), you need clean them one by one
az account show
read -r -p "Are You Sure? [Yes/No] " input
case $input in
[yY][eE][sS])
echo "Yes"
;;
[nN][oO])
echo "No"
exist 1
;;
*)
echo "Invalid input..."
exit 1
;;
esac
id=$(az account show |jq -r '.id')
# clean blueprint assignments
assignments=$(az blueprint assignment list --subscription ${id} |jq -r '.[].name')
for assignment in ${assignments}
do
az blueprint assignment delete --name ${assignment} --subscription ${id} --yes
done
# Get all resource groups
groups=$(az group list --subscription ${id} |jq -r '.[].name')
# clean resource groups
for group in ${groups}
do
az group delete --name ${group} --subscription ${id} --yes --no-wait
done
# clean deleted vaults
vaults=$(az keyvault list-deleted --subscription ${id} |jq -r '.[].name')
for vault in ${vaults}
do
az keyvault purge --name ${vault} --subscription ${id}
done
echo "run this script several times to make sure all resources are cleaned"