Azure – Getting Output Values from Linked ARM Template

azureazure-arm-template

hoping someone can help pinpoint what's missing in my approach.

I'm using visual studio 2017 if this makes any difference.

I've two arm templates; maintemplate and the linkedtemplate.

In the maintemplate I'm trying to reference a linked template and retrieve an output value from it in my maintemplate's outputs section so that the outputs contains values from both the templates.

Here is the linkedtempalte outputs section;

"outputs": {
    "LoadBalancer-pip1": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName1'))).IpAddress]"
    },
    "LoadBalancer-pip1-DNS-Name": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName1'))).dnsSettings.fqdn]"
    }
  }

Here is the maintemplate outputs section;

"outputs": {
    "jump Box VM Public IP address": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',variables('hub-cc-jbox-pipName'))).IpAddress]"
    },
    "Load Balancer VIP1": {
      "type": "string",
      "value": "[reference('hub-plb').outputs.LoadBalancer-pip1.value]"
    },
    "Load Balancer VIP1 DNS Name": {
      "type": "string",
      "value": "[reference('hub-plb').outputs.LoadBalancer-pip1-DNS-Name.value]"
    }
}

Accordingly to this link; https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates#link-or-nest-a-template

it should be possible as long as it's not a nested template, which it's not.

Here is my maintemplate section where I'm making the link to the linkedtempalte;

{
        "name": "hub-plb",
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2017-05-10",
        "dependsOn": [],
        "properties": {
          "mode": "Incremental",
          "templateLink": {
            "uri": "[concat(parameters('_artifactsLocation'), '/', variables('hub-plbTemplateFolder'), '/', variables('hub-plbTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
            "contentVersion": "1.0.0.0"
          },
          "parametersLink": {
            "uri": "[concat(parameters('_artifactsLocation'), '/', variables('hub-plbTemplateFolder'), '/', variables('hub-plbTemplateParametersFileName'), parameters('_artifactsLocationSasToken'))]",
            "contentVersion": "1.0.0.0"
          }
        }
      }

When I try to validate / deploy the template it fails with this message;

VERBOSE: Performing the operation "Creating Deployment" on target "xyz-rg".
08:23:09 - New-AzureRmResourceGroupDeployment : 8:23:08 AM - Error: Code=InvalidTemplate; Message=Deployment template validation 
08:23:09 - failed: 'The template output 'Load Balancer VIP1' at line '1034' and column '31' is not valid: The language expression 
08:23:09 - 'reference('hub-plb').outputs.LoadBalancer-pip1.value' is not valid: the string character 'p' at position '42' is not 
08:23:09 - expected..

Any help much appreciated.

Best Answer

In this case the problem was with the output name, after removing the - from it, everything started to work.

Related Topic