2

I am using azure.mgmt.resource for deleting a resource group from azure but can i delete a particular resource without deleting a resource group?

Narinder Verma
  • 153
  • 2
  • 16

2 Answers2

2

If you can't use the specific client of the resource type as explained in another answer, you can use one of the two generic delete in the azure-mgmt-resource package and the ResourceManagementClient:

Note that the ApiVersion asked is the one from the resource you want to delete. Please look at the RestAPI documentation to get an ApiVersion depending of the resource type you want to delete. For instance, you can get the ApiVersion of Storage in that page:

https://learn.microsoft.com/rest/api/storagerp/

Laurent Mazuel
  • 3,422
  • 13
  • 27
  • Can you please tell how to use this? @laurent – Narinder Verma Dec 22 '17 at 07:47
  • I am using it like following :- credentials = ServicePrincipalCredentials(client_id=clientid,secret=clientsecret,tenant=tenantid) client = ResourceManagementClient(credentials,subscription_id) delete_async_operation = client.resourceoperations.delete_by_id(resource_id,api) delete_async_operation.wait() But getting error:- 'ResourceManagementClient' object has no attribute 'resourceoperations' – Narinder Verma Dec 22 '17 at 07:47
  • Start with this sample to understand on to use a ResourceManagementClient https://github.com/Azure-Samples/resource-manager-python-resources-and-groups – Laurent Mazuel Dec 24 '17 at 07:32
0

For example, If you are deleting a VM in a resource group

Delete VM
        print('\nDelete VM')
        async_vm_delete = compute_client.virtual_machines.delete(GROUP_NAME, VM_NAME)
        async_vm_delete.wait()

Azure-Samples/resource-manager-python-resources-and-groups

Manage Azure resources and resource groups with Python:

Additional information: Click here