Error & Fix Linked ARM Template: The language expression property ‘templateLink’ doesn’t exist

For the novice, learning to deploy Azure resources through ARM template deployments, I like share and explain an error and resolution specifically when it comes to using linked arm templates

The Situation

I have am deploying an Azure App Service function app in an ARM template that also calls out to deploy another azure resource as a linked template.
A linked template helps break down a large arm template into smaller templates to follow a modular pattern.

So I developed two arm templates json files. One is the main ARM template and the second is the linked arm template and a 3rd is parameter file json. Upon deploying an arm template from my local machine using the New-AzResourceGroupDeployment cmd, you only provide main arm template and the parameter files as input parameters. The linked arm template is referenced from the main arm template.

$resourceGroupDeployment = New-AzResourceGroupDeployment -Name 'myFunctionAppDeployment' -ResourceGroupName $resourceGroupName `
-TemplateFile .\arm-functionapp-sql-main.json -TemplateParameterFile .\armdeploy-functionappsql.paramaters.json -DeploymentDebugLogLevel All -Mode Complete

The following is a snippet in the main arm template to call the linked template. The reference is through the linke “uri”: “[uri(deployment().properties.templateLink.uri, ‘azuredeploy-rkazurekeyvault.json’)]”.

{
      "apiVersion": "2018-05-01",
      "name": "linkedTemplate",
      "type": "Microsoft.Resources/deployments",
      "properties": {
          "mode": "Incremental",
          "templateLink": {
              "uri": "[uri(deployment().properties.templateLink.uri, 'azuredeploy-rkazurekeyvault.json')]",
              "contentVersion": "1.0.0.0"
          },
          "parameters": {
	    …

When running the New-AzResourceGroupDeployment cmd, you can get an error as follows, “The language expression property ‘templateLink’ doesn’t exist”

New-AzureRmResourceGroupDeployment : 10:43:11 PM - Resource Microsoft.Resources/deployments 'linkedTemplate' failed with message '{
  "error": {
    "code": "InvalidTemplate",
    "message": "Unable to process template language expressions for resource 
'/subscriptions/2dac1c43-b88c-412f-8b6c-xxxxxxxxxxx/resourceGroups/rkfunctionapp-sql/providers/Microsoft.Resources/deployments/linkedTemplate' at line '338' and column 
'9'. 'The language expression property 'templateLink' doesn't exist, available properties are 'template, parameters, mode, debugSetting, provisioningState'.'"
  }
}'

The Cause

ARM templates when deployed are executed within the Azure Resource Manager in the azure cloud. The reference to the my linked template is relative to the location of where my main arm template is located.

I had deployed in the PowerShell above referring to my main arm template as .\arm-functionapp-sql-main.json. That is from the current working directory. The linked template is referenced as

“templateLink”: {
“uri”: “[uri(deployment().properties.templateLink.uri, ‘azuredeploy-rkazurekeyvault.json’)]”

The Resolution

For the templateLink, they need to accessible from an internet http location. Either anonymously or secured with a token in its query string. This can be from a github repo or from an azure storage account.

To resolve in my case, I copied the main arm template and the linked template into a public github repo.

I would run the New-AzResourceGroupDeployment with the -templateURI parameter to the file. As long as the linked template is located in the same folder at the main arm template, then it will be accessible from Azure resource manager.

For example:

$resourceGroupDeployment = New-AzResourceGroupDeployment -Name $resourceGroupName'Deployment' -ResourceGroupName $resourceGroupName `
-TemplateUri 'https://raw.githubusercontent.com/RoyKimYYZ/azuredeploy-functionapp-sql-keyvault/master/azuredeploy-functionapp-sql-main.json' `

Another approach is to set the templateLink URI in the ARM template to the direct http location.

References

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s