Skip to content

Commit a341c7f

Browse files
authored
Merge pull request #233928 from tfitzmac/0410delete
add Python delete operations
2 parents 51b141a + 0e8d526 commit a341c7f

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

articles/azure-resource-manager/management/delete-resource-group.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
title: Delete resource group and resources
33
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.
44
ms.topic: conceptual
5-
ms.date: 10/13/2022
5+
ms.date: 04/10/2023
66
ms.custom: seodec18, devx-track-arm-template
77
---
88

99
# Azure Resource Manager resource group and resource deletion
1010

1111
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.
1212

13+
[!INCLUDE [AI attribution](../../../includes/ai-generated-attribution.md)]
14+
1315
## How order of deletion is determined
1416

1517
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
7880

7981
1. To confirm the deletion, type the name of the resource group
8082

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+
8198
---
8299

83100
## Delete resource
@@ -112,6 +129,29 @@ az resource delete \
112129

113130
1. When prompted, confirm the deletion.
114131

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+
115155
---
116156

117157
## Required access and deletion failures

0 commit comments

Comments
 (0)