1
votes

Is there a recommended and deterministic way to delete resources created by a subscription level deployment ?

So far I see a straightforward way only when the subscription level deployment contains a single resource group. In that case deleting the RG will correctly delete all the resources.

However, if there are several RG-s created by the subscription level deployment, the order of deleting them should be driven by dependency order, and discovering that is not easy. Further on, the subscription level deployment may create other resources as well, listed here.

I could not find any good method for that so far.

1

1 Answers

0
votes

Azure don't have any way to delete the resources that were deployed at subscription level deployment directly.

Alternative way that you can look for

  1. Deployments-Get API will give you the resource ids that were deployed as part of deployment.

GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}?api-version=2021-04-01

  1. collect all the resource ids from (1)

  2. Use 'Resources - Delete By Id' API to delete resource ids (from 2)

DELETE https://management.azure.com/{resourceId}?api-version=2021-04-01

You can use above approach/logic to build a script or a piece of code to automate whole process.