Skip to main content

What-if operation for Bicep Deployment

ยท 2 min read
Hasan Gural

Infrastructure as Code(IaC) is a crucial technique when you need to automate your environment end-to-end. If you're familiar with Terraform, you are probably familiar with the functionality of terraform plan. You might want to see the same capability before deploying Bicep or Azure Resource Manager templates. In order to have this functionality in your environment, you must have AZ CLI or Azure PowerShell. What-if is supported for the resource group, subscription, management group, and tenant-level deployments.

๐Ÿ’ก What-if commands in [Azure PowerShell]โ€‹

Resource group deploymentsโ€‹
New-AzResourceGroupDeployment -Whatif
Subscription level deploymentsโ€‹
New-AzSubscriptionDeployment -Whatif #region 

New-AzDeployment -Whatif
tip

However, you might want to preview the changes and carry on the deployment at the same time hence using the '-Confirm' switch parameter.

Resource group deploymentsโ€‹
New-AzResourceGroupDeployment -Confirm 
Subscription level deploymentsโ€‹
New-AzSubscriptionDeployment -Confirm 

New-AzDeployment -Confirm

๐Ÿ”Œ What-if commands in [Azure CLI]โ€‹

Resource group deploymentsโ€‹
az deployment group what-if --resource-group testrg --name 'rollout01' --template-file 'what-if-after.bicep'
Subscription level deploymentsโ€‹

az deployment sub what-if --location 'WestU'S --template-file 'what-if-after.bicep'

Management group scope deploymentsโ€‹

az deployment mg what-if --management-group-id 'testmg' --location 'westus' --name 'rollout01' --template-file 'what-if-after.bicep'

Tenant scope deploymentsโ€‹

az deployment tenant what-if --location 'westus' --name 'rollout01' --template-file 'what-if-after.bicep'

Result of using what-if operationโ€‹

...