Skip to content

Commit 0568772

Browse files
committed
update whatif
1 parent 9b134be commit 0568772

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,35 @@ The what-if operation lists six different types of changes:
3737

3838
## What-if commands
3939

40-
You can use the what-if operation for deployments at either the subscription or resource group level.
40+
You can use either Azure PowerShell or Azure REST API for the what-if operation.
4141

42-
For PowerShell, use:
42+
### Azure PowerShell
43+
44+
To preview changes, use:
4345

4446
* `Get-AzResourceGroupDeploymentWhatIf` for resource group deployments
4547
* `Get-AzSubscriptionDeploymentWhatIf` or `Get-AzDeploymentWhatIf` for subscription level deployments
4648

49+
Or, you can use the `-Whatif` switch parameter on the deployment command.
50+
51+
* `New-AzResourceGroupDeployment -Whatif` for resource group deployments
52+
* `New-AzSubscriptionDeployment -Whatif` and `New-AzDeployment -Whatif` for subscription level deployments
53+
54+
Or, you can preview the changes before being prompted to continue with the deployment.
55+
56+
* `New-AzResourceGroupDeployment -Confirm` for resource group deployments
57+
* `New-AzSubscriptionDeployment -Confirm` and `New-AzDeployment -Confirm` for subscription level deployments
58+
4759
> [!NOTE]
48-
> Prior to the release of version 2.0.1-alpha5, you used the `New-AzDeploymentWhatIf` command. This command has been replaced by the `Get-Az*DeploymentWhatIf` syntax. If you've used an earlier version, you need to update those commands.
60+
> 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.
4961
50-
You can also run the what-if operation from the `New-AzResourceGroupDeployment`, `New-AzSubscriptionDeployment` and `New-AzDeployment` commands. Use the `-Whatif` switch parameter to run the what-if command. Use the `-Confirm` switch parameter to first run what-if and then have the option to complete the deployment.
62+
### Azure REST API
5163

5264
For REST API, use:
5365

5466
* [Deployments - What If](/rest/api/resources/deployments/whatif) for resource group deployments
5567
* [Deployments - What If At Subscription Scope](/rest/api/resources/deployments/whatifatsubscriptionscope) for subscription level deployments
5668

57-
To learn about subscription level deployments, see [Create resource groups and resources at the subscription level](deploy-to-subscription.md#).
58-
59-
This article demonstrates resource group deployments.
60-
6169
## Result format
6270

6371
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`.
@@ -104,7 +112,7 @@ The following results show the two different output formats:
104112

105113
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.
106114

107-
```azurepowershell-interactive
115+
```azurepowershell
108116
New-AzResourceGroup `
109117
-Name ExampleGroup `
110118
-Location centralus
@@ -117,7 +125,7 @@ New-AzResourceGroupDeployment `
117125

118126
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`.
119127

120-
```azurepowershell-interactive
128+
```azurepowershell
121129
Get-AzResourceGroupDeploymentWhatIf `
122130
-ResourceGroupName ExampleGroup `
123131
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json" `
@@ -157,7 +165,7 @@ Some of the properties that are listed as deleted won't actually change. In the
157165

158166
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.
159167

160-
```azurepowershell-interactive
168+
```azurepowershell
161169
Get-AzResourceGroupDeploymentWhatIf `
162170
-ResourceGroupName ExampleGroup `
163171
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/empty-template/azuredeploy.json" `
@@ -196,9 +204,9 @@ It's important to remember what-if makes no actual changes. The storage account
196204

197205
## Confirm before deployment
198206

199-
To preview changes before deploying a template, use the `-Confirm` switch parameter with the deployment command. If the changes are as you expected, you can then confirm that you want the deployment to complete. The following command allows you to preview changes before the template is deployed.
207+
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. The following command allows you to preview changes before the template is deployed.
200208

201-
```powershell
209+
```azurepowershell
202210
New-AzResourceGroupDeployment `
203211
-ResourceGroupName ExampleGroup `
204212
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/empty-template/azuredeploy.json" `
@@ -234,6 +242,26 @@ Are you sure you want to execute the deployment?
234242
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
235243
```
236244

245+
## Programmatically evaluate what-if results
246+
247+
You can programmatically evaluate the what-if results by setting the command to a variable.
248+
249+
```azurepowershell
250+
$results = Get-AzResourceGroupDeploymentWhatIf `
251+
-ResourceGroupName ExampleGroup `
252+
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json" `
253+
-storageAccountType Standard_GRS
254+
```
255+
256+
You can see a summary of each change.
257+
258+
```azurepowershell
259+
foreach ($change in $results.Changes)
260+
{
261+
$change.Delta
262+
}
263+
```
264+
237265
## Next steps
238266

239267
- 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).

0 commit comments

Comments
 (0)