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
@@ -13,12 +13,72 @@ Before deploying a template, you might want to preview the changes that will hap
13
13
> [!NOTE]
14
14
> The what-if operation is currently in preview. To use it, you must [sign up for the preview](https://aka.ms/armtemplatepreviews). 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 `New-AzDeploymentWhatIf`PowerShell command or the [Deployments - What If](/rest/api/resources/deployments/whatif)REST operation.
16
+
You can use the what-if operation with the PowerShell commands or REST API operations.
17
17
18
-
In PowerShell, the output looks like:
18
+
In PowerShell, the output includes color-coded results that help you see the different types of changes.
19
19
20
20

21
21
22
+
The text ouptput is:
23
+
24
+
```powershell
25
+
Resource and property changes are indicated with these symbols:
You can use either Azure PowerShell or Azure REST API for the what-if operation.
54
+
55
+
### Azure PowerShell
56
+
57
+
To see a preview of the changes before deploying a template, add the `-Whatif` switch parameter to the deployment command.
58
+
59
+
*`New-AzResourceGroupDeployment -Whatif` for resource group deployments
60
+
*`New-AzSubscriptionDeployment -Whatif` and `New-AzDeployment -Whatif` for subscription level deployments
61
+
62
+
Or, you can use the `-Confirm` switch parameter to preview the changes and get prompted to continue with the deployment.
63
+
64
+
*`New-AzResourceGroupDeployment -Confirm` for resource group deployments
65
+
*`New-AzSubscriptionDeployment -Confirm` and `New-AzDeployment -Confirm` for subscription level deployments
66
+
67
+
The preceding commands return a text summary that you can manually inspect. To get an object that you can programmatically inspect for changes, use:
68
+
69
+
*`$results = Get-AzResourceGroupDeploymentWhatIf` for resource group deployments
70
+
*`$results = Get-AzSubscriptionDeploymentWhatIf` or `$results = Get-AzDeploymentWhatIf` for subscription level deployments
71
+
72
+
> [!NOTE]
73
+
> Prior to the release of version 2.0.1-alpha5, you used the `New-AzDeploymentWhatIf` command. This command has been replaced by the `Get-AzDeploymentWhatIf`, `Get-AzResourceGroupDeploymentWhatIf`, and `Get-AzSubscriptionDeploymentWhatIf` commands. If you've used an earlier version, you need to update that syntax. The `-ScopeType` parameter has been removed.
74
+
75
+
### Azure REST API
76
+
77
+
For REST API, use:
78
+
79
+
*[Deployments - What If](/rest/api/resources/deployments/whatif) for resource group deployments
80
+
*[Deployments - What If At Subscription Scope](/rest/api/resources/deployments/whatifatsubscriptionscope) for subscription level deployments
81
+
22
82
## Change types
23
83
24
84
The what-if operation lists six different types of changes:
@@ -35,84 +95,191 @@ The what-if operation lists six different types of changes:
35
95
36
96
-**Deploy**: The resource exists, and is defined in the template. The resource will be redeployed. The properties of the resource 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. You only see this condition when [ResultFormat](#result-format) is set to `ResourceIdOnly`.
37
97
38
-
## Deployment scope
98
+
## Result format
99
+
100
+
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.
39
101
40
-
You can use the what-if operation for deployments at either the subscription or resource group level. You set the deployment scope with the `-ScopeType` parameter. The accepted values are `Subscription` and `ResourceGroup`. This article demonstrates resource group deployments.
102
+
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**.
41
103
42
-
To learn about subscription level deployments, see [Create resource groups and resources at the subscription level](deploy-to-subscription.md#).
104
+
The following results show the two different output formats:
43
105
44
-
## Result format
106
+
- Full resource payloads
45
107
46
-
You can control the level of detail that is returned about the predicted changes. Set the `ResultFormat` parameter to `FullResourcePayloads` to get a list of resources what will change and details about the properties that will change. Set the `ResultFormat` parameter to `ResourceIdOnly` to get a list of resources that will change. The default value is `FullResourcePayloads`.
108
+
```powershell
109
+
Resource and property changes are indicated with these symbols:
110
+
- Delete
111
+
+ Create
112
+
~ Modify
47
113
48
-
The following screenshots show the two different output formats:
To see how what-if works, let's runs some tests. First, deploy a template from [Azure Quickstart templates that creates a storage account](https://github.com/Azure/azure-quickstart-templates/blob/master/101-storage-account-create/azuredeploy.json). The default storage account type is `Standard_LRS`. You'll use this storage account to test how changes are reported by what-if.
154
+
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. Run the what-if command but change the storage account type to `Standard_GRS`.
167
+
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 is missing one the original tags, a subnet has been removed, and the address prefix has changed.
Notice at the top of the output that colors are defined to indicate the type of changes.
90
210
91
-
At the bottom of the output, it shows the sku name (storage account type) will be changed from **Standard_LRS** to **Standard_GRS**.
211
+
At the bottom of the output, it shows the tag Owner was deleted. The address prefix changed from 10.0.0.0/16 to 10.0.0.0/15. The subnet named subnet001 was deleted. Remember this changes weren't actually deployed. You see a preview of the changes that will happen if you deploy the template.
212
+
213
+
Some of the properties that are listed as deleted won't actually change. Properties can be incorrectly reported as deleted when they aren't in the template, but are automatically set during deployment as default values. This result is considered "noise" in the what-if response. The final deployed resource will have the values set for the properties. As the what-if operation matures, these properties will be filtered out of the result.
214
+
215
+
## Programmatically evaluate what-if results
216
+
217
+
Now, let's programmatically evaluate the what-if results by setting the command to a variable.
92
218
93
-
Some of the properties that are listed as deleted won't actually change. In the preceding image, these properties are accessTier, encryption.keySource and others in that section. Properties can be incorrectly reported as deleted when they aren't in the template, but are automatically set during deployment as default values. This result is considered "noise" in the what-if response. The final deployed resource will have the values set for the properties. As the what-if operation matures, these properties will be filtered out of the result.
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.
98
237
99
-
```azurepowershell-interactive
100
-
New-AzDeploymentWhatIf `
101
-
-ScopeType ResourceGroup `
238
+
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.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
277
+
```
278
+
279
+
You see the expected changes and can confirm that you want the deployment to run.
112
280
113
281
## Next steps
114
282
115
283
- 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).
116
284
- To deploy templates with Azure PowerShell, see [Deploy resources with Resource Manager templates and Azure PowerShell](deploy-powershell.md).
117
285
- To deploy templates with REST, see [Deploy resources with Resource Manager templates and Resource Manager REST API](deploy-rest.md).
118
-
- To roll back to a successful deployment when you get an error, see [Rollback on error to successful deployment](rollback-on-error.md).
0 commit comments