Skip to content

Commit 7dd79fb

Browse files
committed
update
1 parent 038cc75 commit 7dd79fb

File tree

4 files changed

+70
-70
lines changed

4 files changed

+70
-70
lines changed

articles/azure-resource-manager/bicep/deploy-what-if.md

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ During What-If operations, the evaluation and expansion of `templateLink` aren't
1818

1919
[!INCLUDE [permissions](../../../includes/template-deploy-permissions.md)]
2020

21-
### Install Azure CLI module
21+
### Installation
22+
23+
# [Azure CLI](#tab/azure-cli)
2224

2325
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).
2426

25-
### Install Azure PowerShell module
27+
# [PowerShell](#tab/azure-powershell)
2628

2729
To use what-if in PowerShell, you must have version **4.2 or later of the Az module**.
2830

@@ -34,6 +36,7 @@ Install-Module -Name Az -Force
3436

3537
For more information about installing modules, see [Install Azure PowerShell](/powershell/azure/install-azure-powershell).
3638

39+
---
3740
## Running the what-if operation
3841

3942
### What-if commands
@@ -86,9 +89,15 @@ For REST API, use:
8689
- [Deployments - What If At Management Group Scope](/rest/api/resources/deployments/whatifatmanagementgroupscope) for management group deployments
8790
- [Deployments - What If At Tenant Scope](/rest/api/resources/deployments/whatifattenantscope) for tenant deployments.
8891

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+
8998
### Set up environment
9099

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`:
92101

93102
```bicep
94103
resource vnet 'Microsoft.Network/virtualNetworks@2024-07-01' = {
@@ -126,17 +135,6 @@ resource vnet 'Microsoft.Network/virtualNetworks@2024-07-01' = {
126135

127136
To deploy the Bicep file, use:
128137

129-
# [PowerShell](#tab/azure-powershell)
130-
131-
```azurepowershell
132-
New-AzResourceGroup `
133-
-Name ExampleGroup `
134-
-Location centralus
135-
New-AzResourceGroupDeployment `
136-
-ResourceGroupName ExampleGroup `
137-
-TemplateFile "what-if-before.bicep"
138-
```
139-
140138
# [Azure CLI](#tab/azure-cli)
141139

142140
```azurecli
@@ -148,14 +146,25 @@ az deployment group create \
148146
--template-file "what-if-before.bicep"
149147
```
150148

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+
151160
---
152161

153162
### Test modification
154163

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`:
156165

157166
```bicep
158-
resource vnet 'Microsoft.Network/virtualNetworks@2024-05-01' = {
167+
resource vnet 'Microsoft.Network/virtualNetworks@2024-07-01' = {
159168
name: 'vnet-001'
160169
location: resourceGroup().location
161170
tags: {
@@ -183,6 +192,14 @@ resource vnet 'Microsoft.Network/virtualNetworks@2024-05-01' = {
183192

184193
To view the changes, use:
185194

195+
# [Azure CLI](#tab/azure-cli)
196+
197+
```azurecli
198+
az deployment group what-if \
199+
--resource-group ExampleGroup \
200+
--template-file "what-if-after.bicep"
201+
```
202+
186203
# [PowerShell](#tab/azure-powershell)
187204

188205
```azurepowershell
@@ -192,14 +209,6 @@ New-AzResourceGroupDeployment `
192209
-TemplateFile "what-if-after.bicep"
193210
```
194211

195-
# [Azure CLI](#tab/azure-cli)
196-
197-
```azurecli
198-
az deployment group what-if \
199-
--resource-group ExampleGroup \
200-
--template-file "what-if-after.bicep"
201-
```
202-
203212
---
204213

205214
The what-if output appears similar to:
@@ -208,28 +217,26 @@ The what-if output appears similar to:
208217

209218
The text output is:
210219

211-
```powershell
220+
```bash
212221
Resource and property changes are indicated with these symbols:
213222
- Delete
214223
+ Create
215224
~ Modify
216225

217-
The deployment will update the following scope:
218-
219-
Scope: /subscriptions/./resourceGroups/ExampleGroup
220-
221-
~ Microsoft.Network/virtualNetworks/vnet-001 [2018-10-01]
222-
- tags.Owner: "Team A"
223-
+ properties.enableVmProtection: false
226+
- tags.Owner: "Team A"
227+
+ properties.enableVmProtection: false
224228
~ properties.addressSpace.addressPrefixes: [
225229
- 0: "10.0.0.0/16"
226230
+ 0: "10.0.0.0/15"
227231
]
228232
~ properties.subnets: [
229233
- 0:
230234

231-
name: "subnet001"
232-
properties.addressPrefix: "10.0.0.0/24"
235+
name: "subnet001"
236+
properties.addressPrefix: "10.0.0.0/24"
237+
properties.defaultOutboundAccess: false
238+
properties.privateEndpointNetworkPolicies: "Disabled"
239+
properties.privateLinkServiceNetworkPolicies: "Enabled"
233240

234241
]
235242

@@ -246,15 +253,6 @@ Some of the properties that are listed as deleted won't actually change. Propert
246253

247254
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.
248255

249-
# [PowerShell](#tab/azure-powershell)
250-
251-
```azurepowershell
252-
New-AzResourceGroupDeployment `
253-
-ResourceGroupName ExampleGroup `
254-
-Confirm `
255-
-TemplateFile "what-if-after.bicep"
256-
```
257-
258256
# [Azure CLI](#tab/azure-cli)
259257

260258
```azurecli
@@ -264,41 +262,53 @@ az deployment group create \
264262
--template-file "what-if-after.bicep"
265263
```
266264

265+
# [PowerShell](#tab/azure-powershell)
266+
267+
```azurepowershell
268+
New-AzResourceGroupDeployment `
269+
-ResourceGroupName ExampleGroup `
270+
-Confirm `
271+
-TemplateFile "what-if-after.bicep"
272+
```
273+
267274
---
268275

269276
![Bicep deployment what-if operation output deployment mode complete](./media/deploy-what-if/resource-manager-deployment-whatif-output-confirm.png)
270277

271278
The text output is:
272279

273-
```powershell
280+
```bash
274281
Resource and property changes are indicated with these symbols:
275282
- Delete
276283
+ Create
277284
~ Modify
278285

279286
The deployment will update the following scope:
280287

281-
Scope: /subscriptions/./resourceGroups/ExampleGroup
288+
Scope: /subscriptions/a1bfa635-f2bf-42f1-86b5-848c674fc321/resourceGroups/ExampleGroup
282289

283-
~ Microsoft.Network/virtualNetworks/vnet-001 [2018-10-01]
284-
- tags.Owner: "Team A"
285-
+ properties.enableVmProtection: false
290+
~ Microsoft.Network/virtualNetworks/vnet-001 [2024-07-01]
291+
- properties.privateEndpointVNetPolicies: "Disabled"
292+
- tags.Owner: "Team A"
293+
+ properties.enableVmProtection: false
286294
~ properties.addressSpace.addressPrefixes: [
287295
- 0: "10.0.0.0/16"
288296
+ 0: "10.0.0.0/15"
289297
]
290298
~ properties.subnets: [
291299
- 0:
292300

293-
name: "subnet001"
294-
properties.addressPrefix: "10.0.0.0/24"
301+
name: "subnet001"
302+
properties.addressPrefix: "10.0.0.0/24"
303+
properties.defaultOutboundAccess: false
304+
properties.privateEndpointNetworkPolicies: "Disabled"
305+
properties.privateLinkServiceNetworkPolicies: "Enabled"
295306

296307
]
297308

298309
Resource changes: 1 to modify.
299310

300-
Are you sure you want to execute the deployment?
301-
[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):
302312
```
303313

304314
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
307317

308318
Now, let's programmatically evaluate the what-if results by setting the command to a variable.
309319

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+
310326
# [PowerShell](#tab/azure-powershell)
311327

312328
```azurepowershell
@@ -324,12 +340,6 @@ foreach ($change in $results.Changes)
324340
}
325341
```
326342

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-
333343
---
334344

335345
## Understand what-if results
@@ -378,7 +388,7 @@ The what-if operation lists seven different types of changes:
378388

379389
- **Create**: The resource doesn't currently exist but is defined in the Bicep file. The resource will be created.
380390
- **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).
382392
- **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.
383393
- **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.
384394
- **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.
@@ -471,16 +481,6 @@ Remove-AzResourceGroup -Name ExampleGroup
471481

472482
---
473483

474-
## SDKs
475-
476-
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-
484484
## Next steps
485485

486486
- 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/).
2.7 KB
Loading
12.4 KB
Loading

includes/template-deploy-permissions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ ms.date: 08/04/2025
99

1010
### Required permissions
1111

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

1414
For a list of roles and permissions, see [Azure built-in roles](../articles/role-based-access-control/built-in-roles.md).

0 commit comments

Comments
 (0)