Author – Shefali Kamble, Associate Cloud Engineer
Microsoft has introduced the preview of ARM Template what-if feature which was a private preview initially but lately, this new option for PowerShell has been made available as a public preview which is a great option and can help far most with the template deployment.
What is the What-if feature?
This feature holds the capability of letting you know what your deployment would look like but doesn’t attempt to change anything unless confirmed. It is like getting an overview of the deployment. When a lot of resources are deployed through a template, it is easy to overlook something or have a typo somewhere. Especially with templates running in complete mode, this can cause you to accidentally remove resources you wanted to keep or deploy the wrong resources. The what-if option is still in preview, which means the output is not perfect yet. There can be noise in the output, which means the output says something has changed when it didn’t. This is something to keep in mind when using it.Pre-requisites:
- To use what-if in PowerShell, you must have version 2 or later of the Az module.
- To use what-if in Azure CLI, you must have Azure CLI 2.5.0 or later.
What-if commands:
Using Azure PowerShell:
In order to use the what-if parameter in PowerShell and preview the changes that will take place before the actual deployment, run the following commands and append the what-if parameter to it New-AzResourceGroupDeployment for resource level deployment New-AzSubscriptionDeployment for subscription level deployment- New-AzResourceGroupDeployment -Whatif
- New-AzSubscriptionDeployment -Whatif and New-AzDeployment -Whatif
- New-AzResourceGroupDeployment -Confirm for resource group deployments
- New-AzSubscriptionDeployment -Confirm and New-AzDeployment -Confirm for subscription level deployments
Using Azure CLI:
Similarly, to use the what-if parameter in Azure CLI and preview the changes that will take place before the actual deployment, run the following commands and append the what-if parameter to it az deployment group for resource-level deployment az deployment sub for subscription level deployment- az deployment group what-if
- az deployment sub what-if
- az deployment group create –confirm-with-what-if or -c for resource group deployments
- az deployment sub create –confirm-with-what-if or -c for subscription level deployments
Understanding the format of what-if:
There are types of changes that take place during the template deployment. Let’s understand them one by one- Create – the new resource that has to be deployed is mentioned in the template
- Delete – the resource that needs to be deleted. It isn’t defined in the template but works on only those resources that fall under the complete mode category
- Ignore – the resource that already exists won’t be deployed or modified again
- NoChange – the resource defined in the template already exists will be redeployed again but the properties will remain same
- Modify – the resource defined in the template already exists will be redeployed again and the properties will also change
- Deploy – the resource defined in the template already exists will be redeployed again but the properties may or may not change. The operation returns this change type when it doesn’t have enough information to determine if any properties will change