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

...