Sometimes, I’ve needed to remove all the resources in a resource group without actually having to remove the resource group itself. In the Azure Portal, it’s not possible to do this other than manually selecting each resource individually and deleting it. But now that Cloud Shell has GA’d you can easily use it to accomplish the same thing. It’s really quite simple.
- Create a file on your computer called “removeall.json” and paste in the following contents.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": { },
"variables": { },
"resources": [ ],
"outputs": { }
}
- Launch Cloud Shell in the Azure Portal.
- Select Upload to upload the file to your Cloud Shell.
- CD to the path that Cloud Shell indicated was the upload destination.
- Use the Azure CLI to remove the resources.
az group deployment create --mode complete --template-file ./removeall.json --resource-group docker1
What this is doing is deploying an empty ARM Template to the resource group in complete mode. Complete mode does not attempt to update existing resources, rather it will remove existing resources and then recreate the resources as defined in the ARM template. But since the ARM template you deployed is empty, it will simply remove remove the existing resources and not deploying anything new, an voila, you have an empty resource group without having to recreate it.