Understand deployment modes
Azure Resource Manager supports two deployment modes: incremental and complete.
The default deployment mode is incremental. In this mode, Resource Manager won't delete anything. If resources exist in the resource group but aren't specified in the template, Resource Manager leaves them alone. Resources in the template are added to the resource group if they don't already exist, and if they do exist, Resource Manager updates them to the configuration in the template.
You have to explicitly ask for your deployment to run in complete mode. When you use this mode, resources that exist in Azure but that aren't specified in the template are deleted. Complete mode won't delete all resources in your resource group. Some resource types are exempt.
When you run the command in complete mode, whatever resources you have will be removed if they're not defined in the template file.
In Bicep, you can refer to an existing resource by using the
existing keyword. Referring to a resource in this way won't stop it from being deleted during a deployment in complete mode. You need to define it as a full-fledged resource.
When should I use complete mode?
It might seem like a strange idea to allow Azure to delete your resources like this. However, there's a good reason why you might want to consider it. If all of your infrastructure is defined in templates, then using complete mode means that every time you deploy, you'll make sure that no errant resources are left afterward. In other words, it helps to avoid configuration drift in your environment.
If you know for sure that what's in the template file constitutes the full state of your deployment, then go ahead and use this mode. If you use tools like the Azure CLI or PowerShell to update your state gradually, then incremental mode is the way to go.
Complete mode is available when you deploy to a resource group. If you use templates to deploy resources to a subscription, management group, or a tenant, you won't be able to use complete mode.