|
| 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) |
0 commit comments