Skip to content

Commit a84aff4

Browse files
Merge pull request #106000 from tfitzmac/0228whatif
updating whatif
2 parents ea6c772 + 87d56f0 commit a84aff4

6 files changed

+199
-32
lines changed
Loading
Loading
Loading

articles/azure-resource-manager/templates/template-deploy-what-if.md

Lines changed: 199 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Template deployment what-if (Preview)
33
description: Determine what changes will happen to your resources before deploying an Azure Resource Manager template.
44
author: mumian
55
ms.topic: conceptual
6-
ms.date: 11/20/2019
6+
ms.date: 03/05/2020
77
ms.author: jgao
88
---
99
# Resource Manager template deployment what-if operation (Preview)
@@ -13,12 +13,72 @@ Before deploying a template, you might want to preview the changes that will hap
1313
> [!NOTE]
1414
> 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).
1515
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.
1717

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.
1919

2020
![Resource Manager template deployment what-if operation fullresourcepayload and change types](./media/template-deploy-what-if/resource-manager-deployment-whatif-change-types.png)
2121

22+
The text ouptput is:
23+
24+
```powershell
25+
Resource and property changes are indicated with these symbols:
26+
- Delete
27+
+ Create
28+
~ Modify
29+
30+
The deployment will update the following scope:
31+
32+
Scope: /subscriptions/./resourceGroups/ExampleGroup
33+
34+
~ Microsoft.Network/virtualNetworks/vnet-001 [2018-10-01]
35+
- tags.Owner: "Team A"
36+
~ properties.addressSpace.addressPrefixes: [
37+
- 0: "10.0.0.0/16"
38+
+ 0: "10.0.0.0/15"
39+
]
40+
~ properties.subnets: [
41+
- 0:
42+
43+
name: "subnet001"
44+
properties.addressPrefix: "10.0.0.0/24"
45+
46+
]
47+
48+
Resource changes: 1 to modify.
49+
```
50+
51+
## What-if commands
52+
53+
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+
2282
## Change types
2383

2484
The what-if operation lists six different types of changes:
@@ -35,84 +95,191 @@ The what-if operation lists six different types of changes:
3595

3696
- **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`.
3797

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.
39101

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**.
41103

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:
43105

44-
## Result format
106+
- Full resource payloads
45107

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
47113
48-
The following screenshots show the two different output formats:
114+
The deployment will update the following scope:
49115
50-
- Full resource payloads
116+
Scope: /subscriptions/./resourceGroups/ExampleGroup
51117
52-
![Resource Manager template deployment what-if operation fullresourcepayloads output](./media/template-deploy-what-if/resource-manager-deployment-whatif-output-fullresourcepayload.png)
118+
~ Microsoft.Network/virtualNetworks/vnet-001 [2018-10-01]
119+
- tags.Owner: "Team A"
120+
~ properties.addressSpace.addressPrefixes: [
121+
- 0: "10.0.0.0/16"
122+
+ 0: "10.0.0.0/15"
123+
]
124+
~ properties.subnets: [
125+
- 0:
126+
127+
name: "subnet001"
128+
properties.addressPrefix: "10.0.0.0/24"
129+
130+
]
131+
132+
Resource changes: 1 to modify.
133+
```
53134

54135
- Resource ID only
55136

56-
![Resource Manager template deployment what-if operation resourceidonly output](./media/template-deploy-what-if/resource-manager-deployment-whatif-output-resourceidonly.png)
137+
```powershell
138+
Resource and property changes are indicated with this symbol:
139+
! Deploy
140+
141+
The deployment will update the following scope:
142+
143+
Scope: /subscriptions/./resourceGroups/ExampleGroup
144+
145+
! Microsoft.Network/virtualNetworks/vnet-001
146+
147+
Resource changes: 1 to deploy.
148+
```
57149

58150
## Run what-if operation
59151

60152
### Set up environment
61153

62-
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.
63155

64-
```azurepowershell-interactive
156+
```azurepowershell
65157
New-AzResourceGroup `
66158
-Name ExampleGroup `
67159
-Location centralus
68160
New-AzResourceGroupDeployment `
69161
-ResourceGroupName ExampleGroup `
70-
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json"
162+
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/what-if/what-if-before.json"
71163
```
72164

73165
### Test modification
74166

75-
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.
76168

77-
```azurepowershell-interactive
78-
New-AzDeploymentWhatIf `
79-
-ScopeType ResourceGroup `
169+
```azurepowershell
170+
New-AzResourceGroupDeployment `
171+
-Whatif `
80172
-ResourceGroupName ExampleGroup `
81-
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json" `
82-
-storageAccountType Standard_GRS
173+
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/what-if/what-if-after.json"
83174
```
84175

85-
The what-if output is similar to:
176+
The what-if output appears similar to:
177+
178+
![Resource Manager template deployment what-if operation output](./media/template-deploy-what-if/resource-manager-deployment-whatif-change-types.png)
179+
180+
The text output is:
181+
182+
```powershell
183+
Resource and property changes are indicated with these symbols:
184+
- Delete
185+
+ Create
186+
~ Modify
187+
188+
The deployment will update the following scope:
86189
87-
![Resource Manager template deployment what-if operation output](./media/template-deploy-what-if/resource-manager-deployment-whatif-output.png)
190+
Scope: /subscriptions/./resourceGroups/ExampleGroup
191+
192+
~ Microsoft.Network/virtualNetworks/vnet-001 [2018-10-01]
193+
- tags.Owner: "Team A"
194+
~ properties.addressSpace.addressPrefixes: [
195+
- 0: "10.0.0.0/16"
196+
+ 0: "10.0.0.0/15"
197+
]
198+
~ properties.subnets: [
199+
- 0:
200+
201+
name: "subnet001"
202+
properties.addressPrefix: "10.0.0.0/24"
203+
204+
]
205+
206+
Resource changes: 1 to modify.
207+
```
88208

89209
Notice at the top of the output that colors are defined to indicate the type of changes.
90210

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.
92218

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.
219+
```azurepowershell
220+
$results = Get-AzResourceGroupDeploymentWhatIf `
221+
-ResourceGroupName ExampleGroup `
222+
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/what-if/what-if-after.json"
223+
```
224+
225+
You can see a summary of each change.
226+
227+
```azurepowershell
228+
foreach ($change in $results.Changes)
229+
{
230+
$change.Delta
231+
}
232+
```
94233

95-
### Test deletion
234+
## Confirm deletion
96235

97236
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.
98237

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.
239+
240+
```azurepowershell
241+
New-AzResourceGroupDeployment `
242+
-Confirm `
102243
-ResourceGroupName ExampleGroup `
103244
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/empty-template/azuredeploy.json" `
104245
-Mode Complete
105246
```
106247

107-
Because no resources are defined in the template and the deployment mode is set to complete, the storage account will be deleted.
248+
Because no resources are defined in the template and the deployment mode is set to complete, the virtual network will be deleted.
108249

109250
![Resource Manager template deployment what-if operation output deployment mode complete](./media/template-deploy-what-if/resource-manager-deployment-whatif-output-mode-complete.png)
110251

111-
It's important to remember what-if makes no actual changes. The storage account still exists in your resource group.
252+
The text output is:
253+
254+
```powershell
255+
Resource and property changes are indicated with this symbol:
256+
- Delete
257+
258+
The deployment will update the following scope:
259+
260+
Scope: /subscriptions/./resourceGroups/ExampleGroup
261+
262+
- Microsoft.Network/virtualNetworks/vnet-001
263+
264+
id:
265+
"/subscriptions/./resourceGroups/ExampleGroup/providers/Microsoft.Network/virtualNet
266+
works/vnet-001"
267+
location: "centralus"
268+
name: "vnet-001"
269+
tags.CostCenter: "12345"
270+
tags.Owner: "Team A"
271+
type: "Microsoft.Network/virtualNetworks"
272+
273+
Resource changes: 1 to delete.
274+
275+
Are you sure you want to execute the deployment?
276+
[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.
112280

113281
## Next steps
114282

115283
- 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).
116284
- To deploy templates with Azure PowerShell, see [Deploy resources with Resource Manager templates and Azure PowerShell](deploy-powershell.md).
117285
- 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

Comments
 (0)