'How can I delete individual resources in a resource group in Azure using Bicep?
I am trying to delete specific resources in Azure, like how I was able to use terraform destroy -target in Terraform. But I am not able to do the same when I am using Bicep. Is there a way to achieve this?
Solution 1:[1]
Have a look at using Complete mode as the deployment mode.
When deploying your resources, you specify that the deployment is either an incremental update or a complete update. The difference between these two modes is how Resource Manager handles existing resources in the resource group that aren't in the template.
For both modes, Resource Manager tries to create all resources specified in the template. If the resource already exists in the resource group and its settings are unchanged, no operation is taken for that resource. If you change the property values for a resource, the resource is updated with those new values. If you try to update the location or type of an existing resource, the deployment fails with an error. Instead, deploy a new resource with the location or type that you need.
The default mode is incremental.
Complete mode
In complete mode, Resource Manager deletes resources that exist in the resource group but aren't specified in the template.
Note
Always use the what-if operation before deploying a template in complete mode. What-if shows you which resources will be created, deleted, or modified. Use what-if to avoid unintentionally deleting resources.
You can use the mode parameter to set the deployment mode when you, for instance, are deploying using Azure CLI.
az deployment group create \
--mode Complete \
--name ExampleDeployment \
--resource-group ExampleResourceGroup \
--template-file storage.json
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rickvdbosch |
