I'm working on an ARM template containing APIs of an API Management resource, that have been generated by Azure API Management DevOps Resource Kit.
The ARM template is more than 50,000 lines and when I try to deploy it, I get this error:
InvalidTemplate - Deployment template language expression evaluation failed: 'Unable to parse language expression ' ': expected token 'Identifier' and actual 'EndOfData'.'. Please see https://aka.ms/arm-template-expressions for usage details.
This error doesn't contains any information on the location of the error in my template and the file is too large to be debugged manually.
Is there a tool that could allow to debug an ARM Template with more precise information? (Especially that could gives the line on which the error occurs).
You can use the azure client to syntactically validate the template:
az group deployment validate
--resource-group <rg-name>
--template-file <arm-name>
or if you prefer PowerShell:
Test-AzureRmResourceGroupDeployment
-ResourceGroupName <rg-name>
-TemplateFile <arm-name>
Also, in VSCode (or other IDEs like Rider) you can download the ARM plugin to easily spot errors like these.
Try the extension for visual studio code: https://marketplace.visualstudio.com/items?itemName=msazurermtools.azurerm-vscode-tools
It will give you Intellisense for the ARM template and maybe then you will find the error.
I found the tool provided by Microsoft itself very useful.
arm-ttk is a powershell script that checks your createUIDefinition.json and your mainTemplate.json.
The only downside is that it is bases on powershell and if you are on linux you first have to install pwsh.
Alternatively you can use a docker container.
Related
I'm a beginner at Microsoft Azure so please bear with me. I'm following this tutorial on deploying bicep templates with parameters, my bicep file is the exact same as the one in the tutorial. However, when I attempt to deploy it I get the following error
New-AzResourceGroupDeployment : A parameter cannot be found that matches parameter name 'location'.
The location parameter definitely exists. I'm deploying with the following command:
New-AzResourceGroupDeployment -ResourceGroupName ResourceGroup -TemplateFile c:\Users\Name\Desktop\files\azure\testing\test.bicep -location region -storagename storageaccountname -storagetype Standard_LRS -WhatIf
Any help would be appreciated!
It looks like the tutorial contains an error. In the official documentation, there is no location parameter in the New-AzResourceGroupDeployment cmdlet.
Also, you have already specified a resource group, and the resources you describe with bicep contain a location. So the location parameter makes no sense here - just leave it out!
Note that you can also deploy your bicep files using the Azure CLI. See Deploy local Bicep file
A way to not have to put in the location for a resource if you have all resources in the same location is to make use of
So as long as you have run this command, it will apply for all bicep files you run with it configured as such:
This means you don't need to provide it with every CLI command for bicep.
I followed this tutorial series and found it fantastic:
Beginner
Intermediate
Advanced
What the New-AzResourceGroupDeployment command allows you to do is supply parameter values via PowerShell params. So while the command has its own parameters and location is not one of them, any extra parameters supplied to the command are passed as template parameters. If the template does not have a parameter named location (for example) - you'll see that error.
That error is usually pretty accurate, so the template may very well not have a parameter named location. Check to make sure the file c:\Users\Name\Desktop\files\azure\testing\test.bicep has a location param, and that you've saved the file since changing it (I forget that often).
If that doesn't unblock, share your file/code and that may help debug.
Prerequisites:
DevTest Lab with Azure Repos connected (as a source for ARM Templates)
working ARM template
Custom images in that DTLab
You try to deploy an ARM template and all deployments fail with error:
Please note, that the mentioned in error message snapshot ("mshasstupiderrors") is not mentioned in ARM template (in my case, I've used only standard Windows Server 2019).
The fix is to check if there is a custom image in that DTLab with the name "mshasstupiderrors" which is missing a connected snapshot.
This post is triggered by 7 months of support case battle with MS - they agreed that this an issue (ARM template deployment validation?), but were not able to find a reason asked to close the ticket...
I am trying to replicate an existing Azure resource group using arm templates from the automation script section but running into a warning message about 10 resources types cannot be exported yet. One being Azure data factory. After searching online I found that templates for some resource types are not yet available. While looking at the Deployment section in my resource group, I am able to see a deployment details download link for each resource.
Can those be used to recreate each resource into a new resource group? Or is my best bet downloading the template from the automation script section and manually adding the resources for which the template are not yet available?
Any help would be appreciated.
Some of the warnings I got:
ResourceTypeSchemaNotFound:
***The schema of resource type 'Microsoft.DataFactory/dataFactories' is not available. Resources of this type will not be exported to the
template. (Code: ResourceTypeSchemaNotFound, Target:
Microsoft.DataFactory/dataFactories
ExportTemplateProviderError: all related to sql server
***Could not get resources of the type 'Microsoft.Sql/servers/connectionPolicies'. Resources of this type
will not be exported. (Code: ExportTemplateProviderError, Target:
Microsoft.Sql/servers/connectionPolicies)
***Could not get resources of the type 'Microsoft.Sql/servers/backupLongTermRetentionVaults'
***Could not get resources of the type 'Microsoft.Sql/servers/extendedAuditingSettings'.
The Azure resource group ARM templates from the automation script section are not as comprehensive as they should probably be. For example, it is quite possible to deploy a Data Factory instance from ARM. It provides a reasonable starting point but you will find resources that don't deploy as well as a lot of superfluous cruft.
The approach I take is to start from a clean template in Visual Studio and then construct a project from a blank template or quick-start, then refer to the template documentation and build up from scratch, using your exported ARM template from your resource group to help work out how it should look. This results in a nice clean reusable template project.
Unfortunately I have not found an better way yet.
Am working on Azure Resource Manager Templates(ARM Templates) and VSTS CI&CD. With the help of ARM Templates, I want to deploy AKS (Azure kubernete Service). So before going to deploy, I need to validate my ARM Template in the CI-Build by applying a PowerShell task. But here, at the time of validating my ARM Template “It’s not stopping CI-Build even when the validation fails”. Its giving output as “Validation Completed” as shown in the below picture . Is there any solution to resolve this issue, i.e. I wanted to stop my CI-Build running if any validation fails.
Not sure how does your powershell script look like. But according to the screenshot, the powershell script is executed successfully without any error code return. You can update your powershell script to check the validate result and set the exit code to "1" if the result is "InvalidTemplate". This will make the powershell task fail when the template is valid.
Looks like the resource is defined multiple times in the template. You can remove it and its always a good practice from the PowerShell script to use Test-AzureRmResourceGroupDeployment and validate if the template is valid and has obtained all its parameters and then deploy using New-AzureRmResourceGroupDeployment
Like Eddie said you can try this inside a try{} catch block and return an exception or an exit code to make the VSTS Build pipeline fail, if the script fails.
Normally when i deploy through visual studio _artifactsLocation shows when editing the parameters so what should this be in VSTS and how do I set it?
2018-02-21T08:49:46.1918199Z ##[error]Deployment template validation failed: 'The value for the template parameter '_artifactsLocation' at line '1' and column '182' is not provided. Please see https://aka.ms/arm-deploy/#parameter-file for usage details.'.
2018-02-21T08:49:46.1919769Z ##[error]Task failed while creating or updating the template deployment.
You can specify it in parameters file, then specify the file path in Template parameters input box of Azure Resource Group Deployment task if you are using.
Also, the parameters can be override by specifying in Override template parameters input box of Azure Resource Group Deployment task.
If you are calling script through Azure PowerShell task, you can specify it in the arguments: -ArtifactStagingDirectory, related issue: The value for the template parameter '_artifactsLocation' is not provided
This sounds like you are using the Azure Resource Group deployment template from VS to deploy via VSTS.
It uses MSDeploy as part of the ARM template deployment to deploy your service.
The Powershell script that is generated by the VS project template uploads a ZIP-file containing your service to Blob storage, and puts the URL and other information into _artifactsLocation and other ARM template parameters.
Instead of doing that, you can remove the artifacts related parameters and the MSDeploy resource from the ARM template. Then the template ONLY contains infrastructure related resources.
After this, add a "Deploy to App Service" step in the VSTS Release pipeline after the ARM template deployment. That can then be used to deploy your service code.
If you are using a separate parameters json file, you'll need to initialise the _artifactsLocation and _artifactsLocationSasToken there. You can give them empty strings, like:
"_artifactsLocation": {
"value": ""
},
"_artifactsLocationSasToken": {
"value": ""
},
They should automatically get their values from a PowerShell script. I'm using the AzureResourceManagerTemplateDeployment#3 task, it would probably work with AzureResourceGroupDeployment#2 as well.