Skip to content

Commit c6fd6f7

Browse files
committed
update
1 parent 5bef569 commit c6fd6f7

File tree

2 files changed

+61
-46
lines changed

2 files changed

+61
-46
lines changed
Loading

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

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The what-if operation lists six different types of changes:
9999

100100
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.
101101

102-
Set the format 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`.
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**.
103103

104104
The following results show the two different output formats:
105105

@@ -151,63 +151,95 @@ The following results show the two different output formats:
151151

152152
### Set up environment
153153

154-
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.
155155

156156
```azurepowershell
157157
New-AzResourceGroup `
158158
-Name ExampleGroup `
159159
-Location centralus
160160
New-AzResourceGroupDeployment `
161161
-ResourceGroupName ExampleGroup `
162-
-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"
163163
```
164164

165165
### Test modification
166166

167-
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 for the same virtual network but it has a few changes. It is missing one the original tags, a subnet has been removed, and the address prefix has changed.
168168

169169
```azurepowershell
170-
Get-AzResourceGroupDeploymentWhatIf `
170+
New-AzResourceGroupDeployment `
171+
-Whatif `
171172
-ResourceGroupName ExampleGroup `
172-
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json" `
173-
-storageAccountType Standard_GRS
173+
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/what-if/what-if-after.json"
174174
```
175175

176176
The what-if output appears similar to:
177177

178-
![Resource Manager template deployment what-if operation output](./media/template-deploy-what-if/resource-manager-deployment-whatif-output.png)
178+
![Resource Manager template deployment what-if operation output](./media/template-deploy-what-if/resource-manager-deployment-whatif-change-types.png)
179179

180180
The text output is:
181181

182182
```powershell
183183
Resource and property changes are indicated with these symbols:
184184
- Delete
185+
+ Create
185186
~ Modify
186187
187188
The deployment will update the following scope:
188189
189-
Scope: /subscriptions/./resourceGroups/ExampleGroup
190+
Scope: /subscriptions/3a4176e0-58d3-4bb8-8cc2-9b8776777f27/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"
190203
191-
~ Microsoft.Storage/storageAccounts/storez2wlfuvcm4awc [2019-04-01]
192-
- properties.accessTier: "Hot"
193-
~ properties.supportsHttpsTrafficOnly: true => "true"
194-
~ sku.name: "Standard_LRS" => "Standard_GRS"
204+
]
195205
196206
Resource changes: 1 to modify.
197207
```
198208

199209
Notice at the top of the output that colors are defined to indicate the type of changes.
200210

201-
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.
202214

203-
Some of the properties that are listed as deleted won't actually change. In the preceding image, the accessTier property is listed as being deleted. 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.
215+
## Programmatically evaluate what-if results
216+
217+
Now, let's programmatically evaluate the what-if results by setting the command to a variable.
218+
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+
```
204233

205234
### Test deletion
206235

207236
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.
208237

238+
For this example, you'll use the confirm parameter to verify that you want to continue with the deployment.
239+
209240
```azurepowershell
210-
Get-AzResourceGroupDeploymentWhatIf `
241+
New-AzResourceGroupDeployment `
242+
-Confirm `
211243
-ResourceGroupName ExampleGroup `
212244
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/empty-template/azuredeploy.json" `
213245
-Mode Complete
@@ -225,23 +257,24 @@ Resource and property changes are indicated with this symbol:
225257
226258
The deployment will update the following scope:
227259
228-
Scope: /subscriptions/./resourceGroups/ExampleGroup
260+
Scope: /subscriptions/3a4176e0-58d3-4bb8-8cc2-9b8776777f27/resourceGroups/ExampleGroup
229261
230-
- Microsoft.Storage/storageAccounts/storez2wlfuvcm4awc
262+
- Microsoft.Network/virtualNetworks/vnet-001
231263
232-
id: "/subscriptions/./resourceGroups/ExampleGroup/providers/Microsoft.St
233-
orage/storageAccounts/storez2wlfuvcm4awc"
234-
kind: "StorageV2"
235-
location: "centralus"
236-
name: "storez2wlfuvcm4awc"
237-
sku.name: "Standard_LRS"
238-
sku.tier: "Standard"
239-
type: "Microsoft.Storage/storageAccounts"
264+
id:
265+
"/subscriptions/3a4176e0-58d3-4bb8-8cc2-9b8776777f27/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"
240272
241273
Resource changes: 1 to delete.
242-
```
243274
244-
It's important to remember what-if makes no actual changes. The storage account still exists in your resource group.
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+
```
245278

246279
## Confirm before deployment
247280

@@ -283,25 +316,7 @@ Are you sure you want to execute the deployment?
283316
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
284317
```
285318

286-
## Programmatically evaluate what-if results
287-
288-
You can programmatically evaluate the what-if results by setting the command to a variable.
289-
290-
```azurepowershell
291-
$results = Get-AzResourceGroupDeploymentWhatIf `
292-
-ResourceGroupName ExampleGroup `
293-
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json" `
294-
-storageAccountType Standard_GRS
295-
```
296319

297-
You can see a summary of each change.
298-
299-
```azurepowershell
300-
foreach ($change in $results.Changes)
301-
{
302-
$change.Delta
303-
}
304-
```
305320

306321
## Next steps
307322

0 commit comments

Comments
 (0)