Azure Resource Manager resource group and resource deletion
This article shows how to delete resource groups and resources. It describes how Azure Resource Manager orders the deletion of resources when you delete a resource group.
Delete resource group
Use one of the following methods to delete the resource group.
Use one of the following methods to delete a resource.
Remove-AzResource ` -ResourceGroupName ExampleResourceGroup ` -ResourceName ExampleVM ` -ResourceType Microsoft.Compute/virtualMachines
How order of deletion is determined
When you delete a resource group, Resource Manager determines the order to delete resources. It uses the following order:
All the child (nested) resources are deleted.
Resources that manage other resources are deleted next. A resource can have the
managedByproperty set to indicate that a different resource manages it. When this property is set, the resource that manages the other resource is deleted before the other resources.
The remaining resources are deleted after the previous two categories.
After the order is determined, Resource Manager issues a DELETE operation for each resource. It waits for any dependencies to finish before proceeding.
For synchronous operations, the expected successful response codes are:
For asynchronous operations, the expected successful response is 202. Resource Manager tracks the location header or the azure-async operation header to determine the status of the asynchronous delete operation.
When a delete operation returns an error, Resource Manager retries the DELETE call. Retries happen for the 5xx, 429 and 408 status codes. By default, the time period for retry is 15 minutes.
Resource Manager issues a GET call on each resource that it tried to delete. The response of this GET call is expected to be 404. When Resource Manager gets a 404, it considers the deletion to have completed successfully. Resource Manager removes the resource from its cache.
However, if the GET call on the resource returns a 200 or 201, Resource Manager recreates the resource.
If the GET operation returns an error, Resource Manager retries the GET for the following error code:
- Less than 100
- Greater than 500
For other error codes, Resource Manager fails the deletion of the resource.