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
To use what-if in Azure CLI, you must have Azure CLI 2.14.0 or later. If needed, [install the latest version of Azure CLI](/cli/azure/install-azure-cli).
24
26
25
-
### Install Azure PowerShell module
27
+
#[PowerShell](#tab/azure-powershell)
26
28
27
29
To use what-if in PowerShell, you must have version **4.2 or later of the Az module**.
28
30
@@ -34,6 +36,7 @@ Install-Module -Name Az -Force
34
36
35
37
For more information about installing modules, see [Install Azure PowerShell](/powershell/azure/install-azure-powershell).
36
38
39
+
---
37
40
## Running the what-if operation
38
41
39
42
### What-if commands
@@ -86,9 +89,15 @@ For REST API, use:
86
89
-[Deployments - What If At Management Group Scope](/rest/api/resources/deployments/whatifatmanagementgroupscope) for management group deployments
87
90
-[Deployments - What If At Tenant Scope](/rest/api/resources/deployments/whatifattenantscope) for tenant deployments.
88
91
92
+
You can use the what-if operation through the Azure SDKs.
93
+
94
+
- For Python, use [what-if](/python/api/azure-mgmt-resource/azure.mgmt.resource.resources.v2019_10_01.operations.deploymentsoperations#what-if-resource-group-name--deployment-name--properties--location-none--custom-headers-none--raw-false--polling-true----operation-config-).
95
+
- For Java, use [DeploymentWhatIf Class](/java/api/com.azure.resourcemanager.resources.models.deploymentwhatif).
96
+
- For .NET, use [DeploymentWhatIf Class](/dotnet/api/microsoft.azure.management.resourcemanager.models.deploymentwhatif).
97
+
89
98
### Set up environment
90
99
91
-
To see how what-if works, let's runs some tests. First, deploy a Bicep file that creates a virtual network. You'll use this virtual network to test how changes are reported by what-if. Download a copy of the Bicep file.
100
+
To see how what-if works, let's runs some tests. First, deploy a Bicep file that creates a virtual network. Save the following Bicep file as `what-if-before.bicep`:
@@ -148,14 +146,25 @@ az deployment group create \
148
146
--template-file "what-if-before.bicep"
149
147
```
150
148
149
+
# [PowerShell](#tab/azure-powershell)
150
+
151
+
```azurepowershell
152
+
New-AzResourceGroup `
153
+
-Name ExampleGroup `
154
+
-Location centralus
155
+
New-AzResourceGroupDeployment `
156
+
-ResourceGroupName ExampleGroup `
157
+
-TemplateFile "what-if-before.bicep"
158
+
```
159
+
151
160
---
152
161
153
162
### Test modification
154
163
155
-
After the deployment completes, you're ready to test the what-if operation. This time you deploy a Bicep file that changes the virtual network. It's missing one of the original tags, a subnet has been removed, and the address prefix has changed. Download a copy of the Bicep file.
164
+
After the deployment completes, you're ready to test the what-if operation. This time you deploy a Bicep file that changes the virtual network. Comparing to the preceding example, the following example misses one of the original tags, a subnet has been removed, and the address prefix has changed. Save the following Bicep file as `what-if-after.bicep`:
@@ -246,15 +253,6 @@ Some of the properties that are listed as deleted won't actually change. Propert
246
253
247
254
To preview changes before deploying a Bicep file, use the confirm switch parameter with the deployment command. If the changes are as you expected, respond that you want the deployment to complete.
248
255
249
-
# [PowerShell](#tab/azure-powershell)
250
-
251
-
```azurepowershell
252
-
New-AzResourceGroupDeployment `
253
-
-ResourceGroupName ExampleGroup `
254
-
-Confirm `
255
-
-TemplateFile "what-if-after.bicep"
256
-
```
257
-
258
256
# [Azure CLI](#tab/azure-cli)
259
257
260
258
```azurecli
@@ -264,41 +262,53 @@ az deployment group create \
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
311
+
Are you sure you want to execute the deployment? (y/n):
302
312
```
303
313
304
314
You see the expected changes and can confirm that you want the deployment to run.
@@ -307,6 +317,12 @@ You see the expected changes and can confirm that you want the deployment to run
307
317
308
318
Now, let's programmatically evaluate the what-if results by setting the command to a variable.
309
319
320
+
# [Azure CLI](#tab/azure-cli)
321
+
322
+
```azurecli
323
+
results=$(az deployment group what-if --resource-group ExampleGroup --template-file "what-if-after.bicep" --no-pretty-print)
324
+
```
325
+
310
326
# [PowerShell](#tab/azure-powershell)
311
327
312
328
```azurepowershell
@@ -324,12 +340,6 @@ foreach ($change in $results.Changes)
324
340
}
325
341
```
326
342
327
-
# [Azure CLI](#tab/azure-cli)
328
-
329
-
```azurecli
330
-
results=$(az deployment group what-if --resource-group ExampleGroup --template-file "what-if-after.bicep" --no-pretty-print)
331
-
```
332
-
333
343
---
334
344
335
345
## Understand what-if results
@@ -378,7 +388,7 @@ The what-if operation lists seven different types of changes:
378
388
379
389
-**Create**: The resource doesn't currently exist but is defined in the Bicep file. The resource will be created.
380
390
-**Delete**: This change type only applies when using [complete mode](../templates/deployment-modes.md) for JSON template deployment. The resource exists, but isn't defined in the Bicep file. With complete mode, the resource will be deleted. Only resources that [support complete mode deletion](../templates/deployment-complete-mode-deletion.md) are included in this change type.
381
-
-**Ignore**: The resource exists, but isn't defined in the Bicep file. The resource won't be deployed or modified. When you reach the limits for expanding nested templates, you'll encounter this change type. See [What-if limits](#what-if-limits).
391
+
-**Ignore**: The resource exists, but isn't defined in the Bicep file. The resource won't be deployed or modified. When you reach the limits for expanding nested templates, you'll encounter this change type. See [What-if limits](#limitations).
382
392
-**NoChange**: The resource exists, and is defined in the Bicep file. The resource will be redeployed, but the properties of the resource won't change. This change type is returned when [ResultFormat](#result-format) is set to `FullResourcePayloads`, which is the default value.
383
393
-**NoEffect**: The property is ready-only and will be ignored by the service. For example, the `sku.tier` property is always set to match `sku.name` in the [`Microsoft.ServiceBus`](/azure/templates/microsoft.servicebus/namespaces) namespace.
384
394
-**Modify**: The resource exists, and is defined in the Bicep file. The resource will be redeployed, and the properties of the resource will change. This change type is returned when [ResultFormat](#result-format) is set to `FullResourcePayloads`, which is the default value.
You can use the what-if operation through the Azure SDKs.
477
-
478
-
- For Python, use [what-if](/python/api/azure-mgmt-resource/azure.mgmt.resource.resources.v2019_10_01.operations.deploymentsoperations#what-if-resource-group-name--deployment-name--properties--location-none--custom-headers-none--raw-false--polling-true----operation-config-).
479
-
480
-
- For Java, use [DeploymentWhatIf Class](/java/api/com.azure.resourcemanager.resources.models.deploymentwhatif).
481
-
482
-
- For .NET, use [DeploymentWhatIf Class](/dotnet/api/microsoft.azure.management.resourcemanager.models.deploymentwhatif).
483
-
484
484
## Next steps
485
485
486
486
- To use the what-if operation in a pipeline, see [Test ARM templates with What-If in a pipeline](https://4bes.nl/2021/03/06/test-arm-templates-with-what-if/).
Copy file name to clipboardExpand all lines: includes/template-deploy-permissions.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,6 @@ ms.date: 08/04/2025
9
9
10
10
### Required permissions
11
11
12
-
To deploy a Bicep file or ARM template, you need write access on the resources you're deploying and access to all operations on the Microsoft.Resources/deployments resource type. For example, to deploy a virtual machine, you need `Microsoft.Compute/virtualMachines/write` and `Microsoft.Resources/deployments/*` permissions. The what-if operation has the same permission requirements.
12
+
To deploy a Bicep file or ARM template, you need write access on the resources you're deploying and access to all operations on the `Microsoft.Resources/deployments` resource type. For example, to deploy a virtual machine, you need `Microsoft.Compute/virtualMachines/write` and `Microsoft.Resources/deployments/*` permissions. The what-if operation has the same permission requirements.
13
13
14
14
For a list of roles and permissions, see [Azure built-in roles](../articles/role-based-access-control/built-in-roles.md).
0 commit comments