Azure 资源管理器资源组和资源删除Azure Resource Manager resource group and resource deletion

本文介绍如何删除资源组和资源。This article shows how to delete resource groups and resources. 它介绍在删除资源组时 Azure 资源管理器如何为资源的删除排序。It describes how Azure Resource Manager orders the deletion of resources when you delete a resource group.

如何确定删除顺序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:

  1. 删除所有子(嵌套)资源。All the child (nested) resources are deleted.

  2. 接下来,删除管理其他资源的资源。Resources that manage other resources are deleted next. 可以为资源设置 managedBy 属性,用于指示管理它的其他资源。A resource can have the managedBy property 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.

  3. 删除前两种类别后,便会删除剩余资源。The remaining resources are deleted after the previous two categories.

确定顺序后,资源管理器为每个资源发出 DELETE 操作。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:

  • 200200
  • 204204
  • 404404

对于异步操作,预期的成功响应代码为 202。For asynchronous operations, the expected successful response is 202. 资源管理器会跟踪 location 标头或 azure-async operation 标头,以确定异步删除操作的状态。Resource Manager tracks the location header or the azure-async operation header to determine the status of the asynchronous delete operation.

删除错误Deletion errors

如果删除操作返回错误,资源管理器会重试 DELETE 调用。When a delete operation returns an error, Resource Manager retries the DELETE call. 若状态代码为 5xx、429 和 408,便会重试。Retries happen for the 5xx, 429 and 408 status codes. 默认情况下,重试的时间段为 15 分钟。By default, the time period for retry is 15 minutes.

删除之后After deletion

资源管理器对其尝试删除的每个资源发出 GET 调用。Resource Manager issues a GET call on each resource that it tried to delete. 此 GET 调用的响应应为 404。The response of this GET call is expected to be 404. 当资源管理器获得 404 时,便将删除操作视为成功完成。When Resource Manager gets a 404, it considers the deletion to have completed successfully. 资源管理器会从其缓存中删除资源。Resource Manager removes the resource from its cache.

但是,如果对资源的 GET 调用返回 200 或 201,资源管理器会重新创建资源。However, if the GET call on the resource returns a 200 or 201, Resource Manager recreates the resource.

如果 GET 操作返回错误,资源管理器会为以下错误代码重试 GET 调用:If the GET operation returns an error, Resource Manager retries the GET for the following error code:

  • 小于 100Less than 100
  • 408408
  • 429429
  • 大于 500Greater than 500

对于其他错误代码,它会将删除操作视为失败。For other error codes, Resource Manager fails the deletion of the resource.


资源组删除不可逆。Resource Group deletion is irreversible.

删除资源组Delete resource group

使用以下方法之一删除资源组。Use one of the following methods to delete the resource group.

Remove-AzResourceGroup -Name ExampleResourceGroup

删除资源Delete resource

使用以下方法之一删除资源。Use one of the following methods to delete a resource.

Remove-AzResource `
  -ResourceGroupName ExampleResourceGroup `
  -ResourceName ExampleVM `
  -ResourceType Microsoft.Compute/virtualMachines

所需访问权限Required access

若要删除资源组,你需要访问“Microsoft.Resources/subscriptions/resourceGroups”资源的删除操作。To delete a resource group, you need access to the delete action for the Microsoft.Resources/subscriptions/resourceGroups resource. 还需要资源组中所有资源的删除权限。You also need delete for all resources in the resource group.

有关操作的列表,请参阅 Azure 资源提供程序操作For a list of operations, see Azure resource provider operations. 有关内置角色的列表,请参阅 Azure 内置角色For a list of built-in roles, see Azure built-in roles.

如果拥有所需的访问权限,但删除请求失败,则可能是因为资源组上存在If you have the required access, but the delete request fails, it may be because there's a lock on the resource group.

后续步骤Next steps