Last active
November 5, 2020 16:01
-
-
Save kmcquade/512eb33c014ec8279704fa5b6a398b7c to your computer and use it in GitHub Desktop.
Nuke every Azure resource group in every Azure subscription
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
for sub in `az account list | jq -r '.[].id'`; do \ | |
for rg in `az group list --subscription $sub | jq -r '.[].name'`; do \ | |
az group delete --name ${rg} --subscription $sub --no-wait --yes; \ | |
done; done; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "null_resource" "nuke" { | |
# Because we set this to timestamp, it *always* runs :D | |
triggers = { | |
party_like_its_jan_1_1970 = timestamp() | |
} | |
provisioner "local-exec" { | |
command = <<EOF | |
for sub in `az account list | jq -r '.[].id'`; do \ | |
for rg in `az group list --subscription $sub | jq -r '.[].name'`; do \ | |
az group delete --name $rg --subscription $sub --no-wait --yes; \ | |
done; \ | |
done; | |
EOF | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loop through subscriptions | |
for sub in `az account list | jq -r '.[].id'`; do | |
# Loop through resource groups | |
for rg in `az group list --subscription $sub | jq -r '.[].name'`; do | |
# Delete every resource group in the subscription | |
# az group delete --name ${rg} --subscription $sub --no-wait --yes; \ | |
# Use the line below instead to just show the resource group details instead | |
az group show --name $rg --subscription $sub; | |
done; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test run (non destructive)
A less destructive alternative: This lets you just show the details behind each resource group.
Test run one-liner