IFI Techsolutions

How to perform “Dry Run” using ARM Templates

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 […]

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.
Note: PowerShell Core (6.x or 7.x) is required. You can’t install the required module on PowerShell 5.x or earlier.

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 [dt_highlight color=”grey” text_color=”” bg_color=””]New-AzResourceGroupDeployment[/dt_highlight] for resource level deployment [dt_highlight color=”grey” text_color=”” bg_color=””]New-AzSubscriptionDeployment[/dt_highlight] for subscription level deployment
  • [dt_highlight color=”grey” text_color=”” bg_color=””]New-AzResourceGroupDeployment -Whatif[/dt_highlight]
  • [dt_highlight color=”grey” text_color=”” bg_color=””]New-AzSubscriptionDeployment -Whatif[/dt_highlight] and [dt_highlight color=”grey” text_color=”” bg_color=””]New-AzDeployment -Whatif[/dt_highlight]
You can -Confirm the changes after the preview by appending the ­-confirm parameter to continue with the deployment.
  • [dt_highlight color=”grey” text_color=”” bg_color=””]New-AzResourceGroupDeployment -Confirm[/dt_highlight] for resource group deployments
  • [dt_highlight color=”grey” text_color=”” bg_color=””]New-AzSubscriptionDeployment -Confirm[/dt_highlight] and [dt_highlight color=”grey” text_color=”” bg_color=””]New-AzDeployment -Confirm[/dt_highlight] 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
  • [dt_highlight color=”grey” text_color=”” bg_color=””]az deployment group what-if[/dt_highlight]
  • [dt_highlight color=”grey” text_color=”” bg_color=””]az deployment sub what-if[/dt_highlight]
You can -Confirm the changes after the preview by appending the ­–confirm-with-what-if parameter to continue with the deployment. Add this switch to az deployment group create or az deployment sub create.
  • [dt_highlight color=”grey” text_color=”” bg_color=””]az deployment group create –confirm-with-what-if[/dt_highlight] or [dt_highlight color=”grey” text_color=”” bg_color=””]-c[/dt_highlight] for resource group deployments
  • [dt_highlight color=”grey” text_color=”” bg_color=””]az deployment sub create –confirm-with-what-if[/dt_highlight] or [dt_highlight color=”grey” text_color=”” bg_color=””]-c[/dt_highlight] 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
  1. Create – the new resource that has to be deployed is mentioned in the template[dt_gap height=”10″ /]
  2. 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[dt_gap height=”10″ /]
  3. Ignore – the resource that already exists won’t be deployed or modified again[dt_gap height=”10″ /]
  4. NoChange – the resource defined in the template already exists will be redeployed again but the properties will remain same[dt_gap height=”10″ /]
  5. Modify – the resource defined in the template already exists will be redeployed again and the properties will also change[dt_gap height=”10″ /]
  6. 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

Let’s understand the working with a demo:

Open PowerShell 7 with “run as administrator” and login to azure with the command Connect-Azaccount.How to perform Copy the link and paste it in the browser, Insert the code and select your account to Login. How to perform How to perform Your subscription will be displayed after the login. Now let’s create a resource group in which all the deployment would take place so that the resources are placed together.How to perform To test the what-if parameter deploy a virtual network with 2 subnets using the following syntax.How to perform The bottom line shows that 3 resources are to be added and the words in green lists all the resources that will be deployed without actually deploying it unless confirmed. In order to deploy these resources confirm the deployment with the following syntax. It will prompt for confirmation to proceed with the deployment, type Y for yes and hit enter.How to perform It will list all the resources that were deployed.How to perform To verify the deployments head towards the Azure Portal and check the Resource Group:How to perform I hope this will help you to perform Dry runs with ARM templates. You can post your thoughts in the comment section.
Leave a Reply

Subscribe to our knowledge library.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare