You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Determine what changes will happen to your resources before deploying an Azure Resource Manager template.
4
4
author: mumian
5
5
ms.topic: conceptual
6
-
ms.date: 04/27/2020
6
+
ms.date: 04/28/2020
7
7
ms.author: jgao
8
8
---
9
9
# ARM template deployment what-if operation (Preview)
10
10
11
-
Before deploying an Azure Resource Manager (ARM) template, you might want to preview the changes that will happen. Azure Resource Manager provides the what-if operation to let you see how resources will change if you deploy the template. The what-if operation doesn't make any changes to existing resources. Instead, it predicts the changes if the specified template is deployed.
11
+
Before deploying an Azure Resource Manager (ARM) template, you can preview the changes that will happen. Azure Resource Manager provides the what-if operation to let you see how resources will change if you deploy the template. The what-if operation doesn't make any changes to existing resources. Instead, it predicts the changes if the specified template is deployed.
12
12
13
13
> [!NOTE]
14
14
> The what-if operation is currently in preview. As a preview release, the results may sometimes show that a resource will change when actually no change will happen. We're working to reduce these issues, but we need your help. Please report these issues at [https://aka.ms/whatifissues](https://aka.ms/whatifissues).
15
15
16
-
You can use the what-if operation with the PowerShell commands or REST API operations.
16
+
You can use the what-if operation with Azure PowerShell, Azure CLI, or REST API operations.
17
17
18
18
## Install PowerShell module
19
19
20
-
To use what-if in PowerShell, you must have PowerShell Core (6.x or 7.x). If you have PowerShell 5.x or earlier, [update your version of PowerShell](/powershell/scripting/install/installing-powershell).
21
-
22
-
After making sure you have the correct version of PowerShell, install a preview version of the Az.Resources module from the PowerShell gallery.
20
+
To use what-if in PowerShell, you must install a preview version of the Az.Resources module from the PowerShell gallery. But, before installing the module, make sure you have PowerShell Core (6.x or 7.x). If you have PowerShell 5.x or earlier, [update your version of PowerShell](/powershell/scripting/install/installing-powershell). You can't install the preview module on PowerShell 5.x or earlier.
23
21
24
22
### Install preview version
25
23
@@ -54,9 +52,13 @@ If you previously installed an alpha version of the what-if module, uninstall th
54
52
55
53
You're ready to use what-if.
56
54
55
+
## Install Azure CLI module
56
+
57
+
To use what-if in Azure CLI, you must have Azure CLI 2.5.0 or later. If needed, [install the latest version of Azure CLI](/cli/azure/install-azure-cli).
58
+
57
59
## See results
58
60
59
-
In PowerShell, the output includes color-coded results that help you see the different types of changes.
61
+
When you use what-if in PowerShell or Azure CLI, the output includes color-coded results that help you see the different types of changes.
60
62
61
63

62
64
@@ -91,11 +93,9 @@ Resource changes: 1 to modify.
91
93
92
94
## What-if commands
93
95
94
-
You can use either Azure PowerShell or Azure REST API for the what-if operation.
95
-
96
96
### Azure PowerShell
97
97
98
-
To see a preview of the changes before deploying a template, add the `-Whatif` switch parameter to the deployment command.
98
+
To preview changes before deploying a template, add the `-Whatif` switch parameter to the deployment command.
99
99
100
100
*`New-AzResourceGroupDeployment -Whatif` for resource group deployments
101
101
*`New-AzSubscriptionDeployment -Whatif` and `New-AzDeployment -Whatif` for subscription level deployments
@@ -110,6 +110,23 @@ The preceding commands return a text summary that you can manually inspect. To g
110
110
*`$results = Get-AzResourceGroupDeploymentWhatIfResult` for resource group deployments
111
111
*`$results = Get-AzSubscriptionDeploymentWhatIfResult` or `$results = Get-AzDeploymentWhatIfResult` for subscription level deployments
112
112
113
+
### Azure CLI
114
+
115
+
To preview changes before deploying a template, use `what-if` with the deployment command.
116
+
117
+
*`az deployment group what-if` for resource group deployments
118
+
*`az deployment sub what-if` for subscription level deployments
119
+
120
+
Or, you can use the `--confirm-with-what-if` parameter to preview the changes and get prompted to continue with the deployment.
121
+
122
+
*`az deployment group create --confirm-with-what-if` for resource group deployments
123
+
*`az deployment sub create --confirm-with-what-if` for subscription level deployments
124
+
125
+
The preceding commands return a text summary that you can manually inspect. To get a JSON object that you can programmatically inspect for changes, use:
126
+
127
+
*`az deployment group what-if --no-pretty-print` for resource group deployments
128
+
*`az deployment sub what-if --no-pretty-print` for subscription level deployments
129
+
113
130
### Azure REST API
114
131
115
132
For REST API, use:
@@ -135,10 +152,17 @@ The what-if operation lists six different types of changes:
135
152
136
153
## Result format
137
154
138
-
You can control the level of detail that is returned about the predicted changes. In the deployment commands (`New-Az*Deployment`), use the **-WhatIfResultFormat** parameter. In the programmatic object commands (`Get-Az*DeploymentWhatIf`), use the **ResultFormat** parameter.
155
+
You control the level of detail that is returned about the predicted changes. You have two options:
156
+
157
+
***FullResourcePayloads** - returns a list of resources that will change and details about the properties that will change
158
+
***ResourceIdOnly** - returns a list of resources that will change
159
+
160
+
The default value is **FullResourcePayloads**.
139
161
140
-
Set the format parameter to **FullResourcePayloads** to get a list of resources that will change and details about the properties that will change. Set the format parameter to **ResourceIdOnly** to get a list of resources that will change. The default value is **FullResourcePayloads**.
162
+
For PowerShell deployment commands, use the `-WhatIfResultFormat` parameter. In the programmatic object commands, use the `ResultFormat` parameter.
141
163
164
+
For Azure CLI, use the `--result-format` parameter.
165
+
142
166
The following results show the two different output formats:
143
167
144
168
- Full resource payloads
@@ -191,6 +215,8 @@ The following results show the two different output formats:
191
215
192
216
To see how what-if works, let's runs some tests. First, deploy a [template that creates a virtual network](https://github.com/Azure/azure-docs-json-samples/blob/master/azure-resource-manager/what-if/what-if-before.json). You'll use this virtual network to test how changes are reported by what-if.
After the deployment completes, you're ready to test the what-if operation. This time deploy a [template that changes the virtual network](https://github.com/Azure/azure-docs-json-samples/blob/master/azure-resource-manager/what-if/what-if-after.json). It's missing one the original tags, a subnet has been removed, and the address prefix has changed.
244
+
After the deployment completes, you're ready to test the what-if operation. This time you deploy a [template that changes the virtual network](https://github.com/Azure/azure-docs-json-samples/blob/master/azure-resource-manager/what-if/what-if-after.json). It's missing one the original tags, a subnet has been removed, and the address prefix has changed.
@@ -269,20 +322,42 @@ foreach ($change in $results.Changes)
269
322
}
270
323
```
271
324
325
+
# [Azure CLI](#tab/azure-cli)
326
+
327
+
```azurecli
328
+
results=$(az deployment group what-if --resource-group ExampleGroup --template-uri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/what-if/what-if-after.json" --no-pretty-print)
329
+
```
330
+
331
+
---
332
+
272
333
## Confirm deletion
273
334
274
335
The what-if operation supports using [deployment mode](deployment-modes.md). When set to complete mode, resources not in the template are deleted. The following example deploys a [template that has no resources defined](https://github.com/Azure/azure-docs-json-samples/blob/master/empty-template/azuredeploy.json) in complete mode.
275
336
276
337
To preview changes before deploying a template, use the `-Confirm` switch parameter with the deployment command. If the changes are as you expected, confirm that you want the deployment to complete.
@@ -320,4 +395,5 @@ You see the expected changes and can confirm that you want the deployment to run
320
395
321
396
- If you notice incorrect results from the preview release of what-if, please report the issues at [https://aka.ms/whatifissues](https://aka.ms/whatifissues).
322
397
- To deploy templates with Azure PowerShell, see [Deploy resources with ARM templates and Azure PowerShell](deploy-powershell.md).
398
+
- To deploy templates with Azure CLI, see [Deploy resources with ARM templates and Azure CLI](deploy-cli.md).
323
399
- To deploy templates with REST, see [Deploy resources with ARM templates and Resource Manager REST API](deploy-rest.md).
0 commit comments