|
2 | 2 | title: Delete resource group and resources
|
3 | 3 | description: Describes how to delete resource groups and resources. It describes how Azure Resource Manager orders the deletion of resources when a deleting a resource group. It describes the response codes and how Resource Manager handles them to determine if the deletion succeeded.
|
4 | 4 | ms.topic: conceptual
|
5 |
| -ms.date: 10/13/2022 |
| 5 | +ms.date: 04/10/2023 |
6 | 6 | ms.custom: seodec18, devx-track-arm-template
|
7 | 7 | ---
|
8 | 8 |
|
9 | 9 | # Azure Resource Manager resource group and resource deletion
|
10 | 10 |
|
11 | 11 | 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.
|
12 | 12 |
|
| 13 | +[!INCLUDE [AI attribution](../../../includes/ai-generated-attribution.md)] |
| 14 | + |
13 | 15 | ## How order of deletion is determined
|
14 | 16 |
|
15 | 17 | When you delete a resource group, Resource Manager determines the order to delete resources. It uses the following order:
|
@@ -78,6 +80,21 @@ az group delete --name ExampleResourceGroup
|
78 | 80 |
|
79 | 81 | 1. To confirm the deletion, type the name of the resource group
|
80 | 82 |
|
| 83 | +# [Python](#tab/azure-python) |
| 84 | + |
| 85 | +```python |
| 86 | +import os |
| 87 | +from azure.identity import AzureCliCredential |
| 88 | +from azure.mgmt.resource import ResourceManagementClient |
| 89 | + |
| 90 | +credential = AzureCliCredential() |
| 91 | +subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"] |
| 92 | + |
| 93 | +resource_client = ResourceManagementClient(credential, subscription_id) |
| 94 | + |
| 95 | +rg_result = resource_client.resource_groups.begin_delete("exampleGroup") |
| 96 | +``` |
| 97 | + |
81 | 98 | ---
|
82 | 99 |
|
83 | 100 | ## Delete resource
|
@@ -112,6 +129,29 @@ az resource delete \
|
112 | 129 |
|
113 | 130 | 1. When prompted, confirm the deletion.
|
114 | 131 |
|
| 132 | +# [Python](#tab/azure-python) |
| 133 | + |
| 134 | +```python |
| 135 | +import os |
| 136 | +from azure.identity import AzureCliCredential |
| 137 | +from azure.mgmt.resource import ResourceManagementClient |
| 138 | + |
| 139 | +credential = AzureCliCredential() |
| 140 | +subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"] |
| 141 | + |
| 142 | +resource_client = ResourceManagementClient(credential, subscription_id) |
| 143 | + |
| 144 | +resource_client.resources.begin_delete_by_id( |
| 145 | + "/subscriptions/{}/resourceGroups/{}/providers/{}/{}".format( |
| 146 | + subscription_id, |
| 147 | + "exampleGroup", |
| 148 | + "Microsoft.Compute", |
| 149 | + "virtualMachines/exampleVM" |
| 150 | + ), |
| 151 | + "2022-11-01" |
| 152 | +) |
| 153 | +``` |
| 154 | + |
115 | 155 | ---
|
116 | 156 |
|
117 | 157 | ## Required access and deletion failures
|
|
0 commit comments