How is resource deletion handled by Bicep? #8504
-
Hi all! 👋🏼 Apologies if this has been discussed previously, I just couldn't find the answers I am looking for. We are currently using Azure DevOps with Azure Cloud for our project, and decided to go with Bicep for our IaC. My only major worry currently is the fact that resource deletion apparently happens differently than in, let's say, Terraform or CloudFormation. If we deploy resources A, B, and C with an initial template and decide later on to remove resource C using the template, simply commenting it out or removing it then redeploying does not result in the resource actually being deleted in the environment. From my understanding, the templates "manage" the resources written within it, but as soon as they're removed from it, they're ignored. I tried two scenarios where I deploy then try to remove a Container Registry using the template, but neither modes succeeded and just ignore it. Is there a different way of removing specific resources from the template AND the cloud via the deployments as opposed to manually? Thank you so much in advance! 🌷 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
You need to use the If I deploy a template that looks like this to create a container registry: resource containerRegistry 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = {
name: 'mynewacrsteffe'
location: 'westeurope'
sku: {
name: 'Basic'
}
properties: {
adminUserEnabled: false
}
} I can remove the container registry from Azure by removing the resource from the template or commenting it out like you mentioned and deploy the template again using Deploying this template using /*
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = {
name: 'mynewacrsteffe'
location: 'westeurope'
sku: {
name: 'Basic'
}
properties: {
adminUserEnabled: false
}
}
*/ |
Beta Was this translation helpful? Give feedback.
-
What do I do if I want to delete the resources created by the Bicep template itself? I am looking for an equivalent command to
|
Beta Was this translation helpful? Give feedback.
-
Sadly, it does not work for deployment of Management Groups, as we do not deploy management groups in a resource group, so what is the option for that? |
Beta Was this translation helpful? Give feedback.
You need to use the
Complete
deployment mode to remove resources. It will remove resources not declared in the template.If I deploy a template that looks like this to create a container registry:
I can remove the container registry from Azure by removing the resource from the template or commenting it out like you mentioned and deploy the template again using
Complete
mode.Deploying this template using
New-AzResourceGroupDeployment -ResourceGroupName acr-rg -TemplateFi…