Just one way to bulk delete Azure resource groups from an Azure subscription.
As of this writing (20210304) there's no way to bulk delete resource groups from the Azure Portal. While there's certainly valid reasons for that, bulk deletion could be helpful when you're hacking your way through some tutorial or trying something new and you've created resources that you no longer need.
- An Azure Subscription
- An Azure resource group or two or seven
- Access to the Azure Portal: https://portal.azure.com
- Azure CLI: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli/
-
If you know your directory name (something like *.onmicrosoft.com) and subscription ID, substitute
{YOUR_DIRECTORY_NAME}
and{YOUR_SUBSCRIPTION_ID}
in this URL and open it in a browser:(If you don't, that's cool too, see Finding resource groups in the Azure Portal for more guidance.)
https://portal.azure.com/#@{YOUR_DIRECTORY_NAME}/resource/subscriptions/{YOUR_SUBSCRIPTION_ID}/resourceGroups
-
Select the resource groups to delete with the checkboxes left of their name and select
Assign Tags
: -
Specify a name for the tag and select
Save
:
If you're comfortable with xargs, you can pipe the output of az group list
into it and delete the tagged items:
az login
az group list --tag "deleteme" --query [].name --output tsv | xargs -otl az group delete --name
-
Execute the script to delete all resource groups matching a tag name.
az login ./delete_rgs_by_tag.sh deleteme
Some things to keep in mind:
-
By default, the script will prompt your confirmation to delete each resource group
-
By default, the script will wait for deletion to complete (including deleting all the resources in the resource group) and this could take minutes
Approving every deletion isn't necessary? Don't need to wait for confirmation that deletion of all resources in the resource group?
Check out the Optional Parameters.
Or, at your own risk, see High Speed Mode.
-
Don't want to approve every deletion?
-
Auto-approve deletion of every resource group matching the tag by passing 'y' as a second argument:
./delete_rgs_by_tag.sh deleteme y
Don't want to wait for all the resources in your resource group to be deleted?
-
Send the delete operations without waiting for results by passing 'n' as a third argument:
./delete_rgs_by_tag.sh deleteme n n
All the paramters in this script:
./delete_rgs_by_tag.sh: Delete all resource groups given a tag
usage: ./delete_rgs_by_tag.sh <tag> <auto approve (y/n)> <wait for completion (y/n)>
example: ./delete_rgs_by_tag.sh deleteme
Whatever, I don't need confirmation at all, just delete the resource groups. You can do that:
./create_keyvault deleteme y n
-
Open a browser and navigate to the Azure Portal https://portal.azure.com/
-
Navigate to the Subscriptions page by using the search bar:
-
Select your subscription from the list
-
Navigate to the Resource Groups blade:
I like Visual Studio Code's Remote - Containers extension because I don't have to worry about what tools are available on my machine.
Instead, when I clone the repo, I get with it all the tools the authors used to create the repo.
For more information see https://code.visualstudio.com/docs/remote/containers/
In their words:
The Visual Studio Code Remote - Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder or repository inside a container and take advantage of Visual Studio Code's full feature set. A devcontainer.json file in your project tells VS Code how to access (or create) a development container with a well-defined tool and runtime stack. This container can be used to run an application or to sandbox tools, libraries, or runtimes needed for working with a codebase.