Skip to content

Commit c0b89e3

Browse files
authored
Merge pull request #178357 from davidsmatlak/ds-tsdocs-1102
Updates ARM troubleshooting docs
2 parents 1570b6c + 286a5ce commit c0b89e3

13 files changed

+401
-207
lines changed

articles/azure-resource-manager/troubleshooting/common-deployment-errors.md

Lines changed: 13 additions & 205 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Create a troubleshooting template
3+
description: Describes how to create a template to troubleshoot Azure resource deployed with Azure Resource Manager templates (ARM templates) or Bicep files.
4+
tags: top-support-issue
5+
ms.topic: troubleshooting
6+
ms.date: 11/02/2021
7+
---
8+
9+
# Create a troubleshooting template
10+
11+
In some cases, the best way to troubleshoot your template is to isolate and test specific parts of it. You can create a troubleshooting template that focuses on the resource that you believe causes the error.
12+
13+
For example, an error occurs when your deployment template references an existing resource. Rather than evaluate an entire deployment template, create a troubleshooting template that returns data about the resource. The output helps you find whether you're passing in the correct parameters, using template functions correctly, and getting the resource you expect.
14+
15+
## Deploy a troubleshooting template
16+
17+
The following ARM template and Bicep file get information from an existing storage account. You run the deployment with Azure PowerShell [New-AzResourceGroupDeployment](/powershell/module/az.resources/new-azresourcegroupdeployment) or Azure CLI [az deployment group create](/cli/azure/deployment/group#az_deployment_group_create). Specify the storage account's name and resource group. The output is an object with the storage account's property names and values.
18+
19+
```json
20+
{
21+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
22+
"contentVersion": "1.0.0.0",
23+
"parameters": {
24+
"storageName": {
25+
"type": "string"
26+
},
27+
"storageResourceGroup": {
28+
"type": "string"
29+
}
30+
},
31+
"variables": {},
32+
"resources": [],
33+
"outputs": {
34+
"exampleOutput": {
35+
"value": "[reference(resourceId(parameters('storageResourceGroup'), 'Microsoft.Storage/storageAccounts', parameters('storageName')), '2021-04-01')]",
36+
"type": "object"
37+
}
38+
}
39+
}
40+
```
41+
42+
In Bicep, use the `existing` keyword and run the deployment from the resource group where the storage account exists. Use `scope` to access a resource in a different resource group. For more information, see [existing resources](../bicep/resource-declaration.md#existing-resources).
43+
44+
```bicep
45+
param storageName string
46+
47+
resource stg 'Microsoft.Storage/storageAccounts@2021-04-01' existing = {
48+
name: storageName
49+
}
50+
51+
output exampleOutput object = stg.properties
52+
```
53+
54+
## Alternate troubleshooting method
55+
56+
If you believe the deployment errors are caused by incorrect dependencies, you can run tests by breaking the template into simplified templates. First, create a template that deploys only a single resource (like a SQL Server). When you're sure the resource deployment is correct, add a resource that depends on it (like a SQL Database). When those two resources are correctly defined, add other dependent resources (like auditing policies). In between each test deployment, delete the resource group to make sure you're adequately testing the dependencies.
57+
58+
## Next steps
59+
60+
- [Common deployment errors](common-deployment-errors.md)
61+
- [Find error codes](find-error-code.md)
62+
- [Enable debug logging](enable-debug-logging.md)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: Enable debug logging
3+
description: Describes how to enable debug logging to troubleshoot Azure resources deployed with Azure Resource Manager templates (ARM templates) or Bicep files.
4+
tags: top-support-issue
5+
ms.topic: troubleshooting
6+
ms.date: 11/02/2021
7+
ms.custom: devx-track-azurepowershell
8+
---
9+
10+
# Enable debug logging
11+
12+
To troubleshoot a deployment error, it helps to gather more information. Use Azure PowerShell to enable debug logging. You can get data about a deployment's request and response to learn the cause of the problem. Debug logging works with Azure Resource Manager templates (ARM templates) and Bicep files.
13+
14+
## Get debug information
15+
16+
# [PowerShell](#tab/azure-powershell)
17+
18+
Use [New-AzResourceGroupDeployment](/powershell/module/az.resources/new-azresourcegroupdeployment) to set the `DeploymentDebugLogLevel` parameter to `All`, `ResponseContent`, or `RequestContent`. When debug logging is enabled, a warning is displayed that secrets like passwords or `listKeys` can be logged by commands like [Get-AzResourceGroupDeploymentOperation](/powershell/module/az.resources/get-azresourcegroupdeploymentoperation).
19+
20+
```azurepowershell
21+
New-AzResourceGroupDeployment `
22+
-Name exampledeployment `
23+
-ResourceGroupName examplegroup `
24+
-TemplateFile azuredeploy.json `
25+
-DeploymentDebugLogLevel All
26+
```
27+
28+
The output shows the debug logging:
29+
30+
```Output
31+
DeploymentDebugLogLevel : RequestContent, ResponseContent
32+
```
33+
34+
To view all the properties for deployment operations:
35+
36+
```azurepowershell
37+
Get-AzResourceGroupDeploymentOperation `
38+
-DeploymentName exampledeployment `
39+
-ResourceGroupName examplegroup
40+
```
41+
42+
You can specify a property. For example, the `StatusMessage` property outputs the same data as the Azure CLI `response` property.
43+
44+
```azurepowershell
45+
(Get-AzResourceGroupDeploymentOperation `
46+
-DeploymentName exampledeployment `
47+
-ResourceGroupName examplegroup).StatusMessage
48+
```
49+
50+
Use Azure CLI to get the debug `request` and `response` information. In Az module versions 4.8 and later, `Get-AzResourceGroupDeploymentOperation` doesn't include those properties in output. For a list of available properties, see [outputs](/powershell/module/az.resources/get-azresourcegroupdeploymentoperation#outputs).
51+
52+
# [Azure CLI](#tab/azure-cli)
53+
54+
You can't enable debug logging with Azure CLI but you can retrieve debug logging data.
55+
56+
Get the deployment operations with the following command:
57+
58+
```azurecli
59+
az deployment operation group list \
60+
--resource-group examplegroup \
61+
--name exampledeployment
62+
```
63+
64+
Get the request content with the following command:
65+
66+
```azurecli
67+
az deployment operation group list \
68+
--name exampledeployment \
69+
--resource-group examplegroup \
70+
--query [].properties.request
71+
```
72+
73+
Get the response content with the following command:
74+
75+
```azurecli
76+
az deployment operation group list \
77+
--name exampledeployment \
78+
--resource-group examplegroup \
79+
--query [].properties.response
80+
```
81+
82+
---
83+
84+
## Nested template
85+
86+
To log debug information for a [nested](../templates/linked-templates.md#nested-template) ARM template, use the [Microsoft.Resources/deployments](/azure/templates/microsoft.resources/deployments) `debugSetting` element.
87+
88+
```json
89+
{
90+
"type": "Microsoft.Resources/deployments",
91+
"apiVersion": "2020-10-01",
92+
"name": "nestedTemplate",
93+
"properties": {
94+
"mode": "Incremental",
95+
"templateLink": {
96+
"uri": "{template-uri}",
97+
"contentVersion": "1.0.0.0"
98+
},
99+
"debugSetting": {
100+
"detailLevel": "requestContent, responseContent"
101+
}
102+
}
103+
}
104+
```
105+
106+
Bicep uses [modules](../bicep/modules.md) rather than `Microsoft.Resources/deployments`. With modules, you can reuse your code to deploy a Bicep file from another Bicep file.
107+
108+
## Next steps
109+
110+
- [Common deployment errors](common-deployment-errors.md)
111+
- [Find error codes](find-error-code.md)
112+
- [Create troubleshooting template](create-troubleshooting-template.md)
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
---
2+
title: Find error codes
3+
description: Describes how to find error codes to troubleshoot Azure resources deployed with Azure Resource Manager templates (ARM templates) or Bicep files.
4+
tags: top-support-issue
5+
ms.topic: troubleshooting
6+
ms.date: 11/02/2021
7+
ms.custom: devx-track-azurepowershell
8+
---
9+
10+
# Find error codes
11+
12+
When an Azure resource deployment fails using Azure Resource Manager templates (ARM templates) or Bicep files, and error code is received. This article describes how to find error codes so you can troubleshoot the problem. For more information about error codes, see [common deployment errors](common-deployment-errors.md).
13+
14+
## Error types
15+
16+
There are three types of errors you can receive:
17+
18+
- **Validation errors** occur before a deployment begins and are caused by syntax errors. To identify validation errors, use [Visual Studio Code](https://code.visualstudio.com) with the latest [Bicep extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep) or [Azure Resource Manager Tools extension](https://marketplace.visualstudio.com/items?itemName=msazurermtools.azurerm-vscode-tools).
19+
- **Preflight validation errors** occur when the deployment begins but resources aren't deployed. For example, an incorrect parameter value or invalid resource name.
20+
- **Deployment errors** occur during deployment and troubleshooting is needed to find the cause.
21+
22+
Validation and preflight error codes are reported in a resource group's activity log, and the subscription's [activity log](../../azure-monitor/essentials/activity-log.md). An exception is Bicep syntax validation that's only shown in the editor or deployment command's output. Deployment error codes are shown in a resource group's deployment history and activity log.
23+
24+
## Validation errors
25+
26+
Templates are validated during the deployment process and error codes are displayed. Before you run a deployment, you can run validation tests with Azure PowerShell or Azure CLI.
27+
28+
# [Portal](#tab/azure-portal)
29+
30+
An ARM template can be deployed from the portal. If the template has syntax errors, you'll see a validation error when you try to run the deployment. For more information about portal deployments, see [deploy resources from custom template](../templates/deploy-portal.md#deploy-resources-from-custom-template).
31+
32+
The following example attempts to deploy a storage account and a validation error occurs.
33+
34+
:::image type="content" source="media/find-error-code/validation-error.png" alt-text="Screenshot of an Azure portal validation error.":::
35+
36+
Select the message for more details. The template has a syntax error with error code `InvalidTemplate`. The **Summary** shows an expression is missing a closing parenthesis.
37+
38+
:::image type="content" source="media/find-error-code/validation-details.png" alt-text="Screenshot of a validation error message that shows a syntax error.":::
39+
40+
# [PowerShell](#tab/azure-powershell)
41+
42+
To validate an ARM template before deployment run [Test-AzResourceGroupDeployment](/powershell/module/az.resources/test-azresourcegroupdeployment). The same error is shown when you run a deployment.
43+
44+
```azurepowershell
45+
Test-AzResourceGroupDeployment `
46+
-ResourceGroupName examplegroup `
47+
-TemplateFile azuredeploy.json
48+
```
49+
50+
The output displays error codes like `InvalidTemplateDeployment` or `AccountNameInvalid` that you can use to troubleshoot and fix the template.
51+
52+
For a Bicep file, the output for a syntax validation problem shows a parameter error.
53+
54+
```Output
55+
Test-AzResourceGroupDeployment: Cannot retrieve the dynamic parameters for the cmdlet.
56+
Cannot find path '/tmp/11111111-1111-1111-1111-111111111111/main.json' because it does not exist.
57+
```
58+
59+
To get more troubleshooting information, use the Bicep [build](../bicep/bicep-cli.md) command. The output shows each error's line and column number in parentheses, and the error message.
60+
61+
```bicep
62+
bicep build main.bicep
63+
```
64+
65+
```Output
66+
/azuredeploy.bicep(22,51) : Error BCP064: Found unexpected tokens in interpolated expression.
67+
/azuredeploy.bicep(22,51) : Error BCP004: The string at this location is not terminated due to an
68+
unexpected new line character.
69+
```
70+
71+
There are more PowerShell cmdlets available to validate deployment templates:
72+
73+
- [Test-AzDeployment](/powershell/module/az.resources/test-azdeployment) for subscription level deployments.
74+
- [Test-AzManagementGroupDeployment](/powershell/module/az.resources/test-azmanagementgroupdeployment)
75+
- [Test-AzTenantDeployment](/powershell/module/az.resources/test-aztenantdeployment)
76+
77+
# [Azure CLI](#tab/azure-cli)
78+
79+
To validate an ARM template before deployment, run [az deployment group validate](/cli/azure/deployment/group#az_deployment_group_validate). The same error is shown when you run a deployment.
80+
81+
```azurecli
82+
az deployment group validate \
83+
--resource-group examplegroup \
84+
--template-file azuredeploy.json
85+
```
86+
87+
The output displays error codes like `InvalidTemplateDeployment` or `AccountNameInvalid` that you can use to troubleshoot and fix the template.
88+
89+
For a Bicep file, the output shows each error's line and column number in parentheses, and the error message.
90+
91+
```azurecli
92+
az deployment group validate \
93+
--resource-group examplegroup \
94+
--template-file main.bicep
95+
```
96+
97+
```Output
98+
/azuredeploy.bicep(22,51) : Error BCP064: Found unexpected tokens in interpolated expression.
99+
/azuredeploy.bicep(22,51) : Error BCP004: The string at this location is not terminated due to an
100+
unexpected new line character.
101+
```
102+
103+
There are more Azure CLI commands available to validate deployment templates:
104+
105+
- [az deployment sub validate](/cli/azure/deployment/sub#az_deployment_sub_validate)
106+
- [az deployment mg validate](/cli/azure/deployment/mg#az_deployment_mg_validate)
107+
- [az deployment tenant validate](/cli/azure/deployment/tenant#az_deployment_tenant_validate)
108+
109+
---
110+
111+
## Deployment errors
112+
113+
Several operations are processed to deploy an Azure resource. Deployment errors occur when an operation passes validation but fails during deployment. You can view messages about each deployment operation and each deployment for a resource group.
114+
115+
# [Portal](#tab/azure-portal)
116+
117+
To see messages about a deployment's operations, use the resource group's **Activity log**:
118+
119+
1. Sign in to [Azure portal](https://portal.azure.com).
120+
1. Go to **Resource groups** and select the deployment's resource group name.
121+
1. Select **Activity log**.
122+
1. Use the filters to find an operation's error log.
123+
124+
:::image type="content" source="./media/find-error-code/activity-log.png" alt-text="Screenshot of the resource group's activity log that highlights a failed deployment.":::
125+
126+
1. Select the error log to see the operation's details.
127+
128+
:::image type="content" source="./media/find-error-code/activity-log-details.png" alt-text="Screenshot of the activity log details that shows a failed deployment's error message.":::
129+
130+
To view a deployment's result:
131+
132+
1. Go to the resource group.
133+
1. Select **Settings** > **Deployments**.
134+
1. Select **Error details** for the deployment.
135+
136+
:::image type="content" source="media/find-error-code/deployment-error-details.png" alt-text="Screenshot of a resource group's link to error details for a failed deployment.":::
137+
138+
1. The error message and error code `NoRegisteredProviderFound` are shown.
139+
140+
:::image type="content" source="media/find-error-code/deployment-error-summary.png" alt-text="Screenshot of a message that shows deployment error details.":::
141+
142+
# [PowerShell](#tab/azure-powershell)
143+
144+
To see a deployment's operations messages with PowerShell, use [Get-AzResourceGroupDeploymentOperation](/powershell/module/az.resources/get-azresourcegroupdeploymentoperation).
145+
146+
To show all the operations for a deployment:
147+
148+
```azurepowershell
149+
Get-AzResourceGroupDeploymentOperation `
150+
-DeploymentName exampledeployment `
151+
-ResourceGroupName examplegroup
152+
```
153+
154+
To specify a specific property type:
155+
156+
```azurepowershell
157+
(Get-AzResourceGroupDeploymentOperation `
158+
-DeploymentName exampledeployment `
159+
-ResourceGroupName examplegroup).StatusCode
160+
```
161+
162+
To get a deployment's result, use [Get-AzResourceGroupDeployment](/powershell/module/az.resources/get-azresourcegroupdeployment).
163+
164+
```azurepowershell
165+
Get-AzResourceGroupDeployment `
166+
-DeploymentName exampledeployment `
167+
-ResourceGroupName examplegroup
168+
```
169+
170+
# [Azure CLI](#tab/azure-cli)
171+
172+
To see a deployment's operations messages with Azure CLI, use [az deployment operation group list](/cli/azure/deployment/operation/group#az_deployment_operation_group_list).
173+
174+
To show all the operations for a deployment:
175+
176+
```azurecli
177+
az deployment operation group list \
178+
--name exampledeployment \
179+
--resource-group examplegroup \
180+
--query "[*].properties"
181+
```
182+
183+
To specify a specific property type:
184+
185+
```azurecli
186+
az deployment operation group list \
187+
--name exampledeployment \
188+
--resource-group examplegroup \
189+
--query "[*].properties.statusCode"
190+
```
191+
192+
To get a deployment's result, use [az deployment group show](/cli/azure/deployment/group#az_deployment_group_show).
193+
194+
```azurecli
195+
az deployment group show \
196+
--resource-group examplegroup \
197+
--name exampledeployment
198+
```
199+
200+
---
201+
202+
## Next steps
203+
204+
- [Common deployment errors](common-deployment-errors.md)
205+
- [Enable debug logging](enable-debug-logging.md)
206+
- [Create troubleshooting template](create-troubleshooting-template.md)
52.1 KB
Loading
51.4 KB
Loading
44.8 KB
Loading

0 commit comments

Comments
 (0)