One of the cool features that Bicep has to offer is the 'what-if' operation. This allows you to preview the changes that will happen when applying your bicep template.
Let’s see this operation in action:
- Open a command prompt
- Let’s first check if we have a version of the Azure CLI installed that supports the ‘what-if’ operation:
az version
The output should look like this:
{
"azure-cli": "2.54.0",
"azure-cli-core": "2.54.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {
"connectedk8s": "1.2.0",
"customlocation": "0.1.3",
"k8s-configuration": "1.1.1",
"k8s-extension": "1.0.4"
}
}
- This should return at least CLI version 2.14.0. If not first install the latest version of the Azure CLI.
- Now we can run the command that we originally want to execute but replace the create operation with what-if. For example:
az deployment group what-if --name BicepSWA --resource-group Cloudbrew2023 --mode Incremental --template-file astro.bicep
The ouput should look like this:
It nicely states what will be created, modified or ignored.
Remark: Notice that Bicep will not remove any resources if you use the default incremental deployment mode as Bicep don’t know if it has created the resource or not.
More information
Template deployment what-if - Azure Resource Manager | Microsoft Learn