Preview a Bicep deployment with what-if
In this task you'll see exactly what a Bicep deployment will change before it runs.
Bicep is Azure's own infrastructure-as-code language: a shorter way to write ARM templates, with no state file because Azure itself is the record. az deployment group create -f main.bicep deploys it.
What-if is the preview: it compares the file with what's deployed and lists each resource as create (+), modify (~), delete (-) or no change. In the default incremental mode, resources missing from the file are left alone, but properties you do list (such as tags or inline NSG rules) replace what's there.
Example. A what-if on SS Kaiser's storage change showed the purpose and lab tags would be deleted, because the new file listed only owner. Adding them took a minute; finding the missing tags after a cost report would have taken a week.
Before you start
You need: Contributor on a resource group. Time: 20 minutes.
Where to look
- Cloud Shell
- az deployment group what-if
- az deployment group create
Steps
- Write main.bicep, or
az bicep decompilean exported template to start from what's there. - Preview:
az deployment group what-if -g <group> -f main.bicep. Read every ~ and - line. - Deploy with a name you can find later:
az deployment group create -g <group> -f main.bicep -n <name>. - Run the what-if again: no changes means the file and Azure match. Run it on a schedule to catch drift.
Commands
az deployment group what-if -g <group> -f main.bicep
az deployment group create -g <group> -f main.bicep -n <name>
Watch out for
- Cost
- Bicep and what-if are free; you pay for what you deploy.
- Security
- Never put secrets in a .bicep file or its parameters file; reference Key Vault instead.
- Common mistakes
- Skipping the what-if, and trusting it blindly: some properties show as changes every time (noise), so learn which ones.
Clean up
Delete what you deployed, usually by deleting the resource group.
Words to know
- Bicep
- Azure's infrastructure-as-code language, compiled to ARM templates.
- What-if
- A preview of what a deployment would create, change or delete.
- Incremental mode
- The default deployment mode: adds and updates, never deletes resources missing from the file.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands On