0
votes

I am using a series of json ARM templates to deploy Azure VMs, and am having issues passing information from one resource deployment to another.

I deploy two resources using linked templates from blob storage, one which in and of itself deploys nothing, but returns an object populated with configuration settings, and a second which then passes that output of configuration settings to another template as a parameter:

  "resources": [
    {
      "name": "[concat(deployment().name, '-config')]",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2016-09-01",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[variables('configurationTemplate')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "subscriptionParameters": { "value": "[variables('subscriptionParameters')]" }
        }
      }
    },
    {
      "name": "[concat(deployment().name, '-vm')]",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2016-09-01",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[variables('vmTemplate')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "configuration": { "value": "[reference(concat(deployment().name, '-config').outputs.configuration.value)]" },
          "vmName": { "value": "[parameters('vmName')]" },
          "vmSize": { "value": "[parameters('vmSize')]" },
          "os": { "value": "[parameters('os')]" },
          "managedDiskTier": { "value": "[parameters('managedDiskTier')]" },
          "dataDisksToProvision": { "value": "[parameters('dataDisksToProvision')]" },
          "dataDiskSizeGB": { "value": "[parameters('dataDiskSizeGB')]" },
          "domainJoined": { "value": "[parameters('domainJoined')]" },
          "localAdminUsername": { "value": "[parameters('localAdminUsername')]" },
          "localAdminPassword": { "value": "[parameters('localAdminPassword')]" },
          "numberOfNics": { "value": "[parameters('numberOfNics')]" },
          "subnetName": { "value": "[parameters('subnetName')]" },
          "highlyAvailable": { "value": "[parameters('highlyAvailable')]" },
          "availabilitySetName": { "value": "[parameters('availabilitySetName')]" },
          "availabilitySetUpdateDomains": { "value": "[parameters('availabilitySetUpdateDomains')]" },
          "availabilitySetFaultDomains": { "value": "[parameters('availabilitySetFaultDomains')]" }
        }
      }
    }
  ],
  "outputs": {
    "configuration": {
      "type": "object",
      "value": "[reference(concat(deployment().name, '-config')).outputs.configuration.value]"
    }
  }

Deploying the first resource on it's own succeeds, and the output [reference(concat(deployment().name, '-config')).outputs.configuration.value] is correctly returned, and contains all the correct information and is well formed.

If I then add the second resource into the mix, then the deployment fails with the following error:

08:57:41 - [ERROR] New-AzureRmResourceGroupDeployment : 08:57:41 - Error: Code=InvalidTemplate; 
08:57:41 - [ERROR] Message=Deployment template validation failed: 'The template resource 
08:57:41 - [ERROR] 'rcss.test.vm-0502-0757-rcss-vm' at line '317' and column '6' is not valid: 
08:57:41 - [ERROR] The language expression property 'Microsoft.WindowsAzure.ResourceStack.Frontdoo
08:57:41 - [ERROR] r.Expression.Expressions.JTokenExpression' can't be evaluated.. Please see 
08:57:41 - [ERROR] https://aka.ms/arm-template-expressions for usage details.'.

If I remove the "configuration" parameter from both this parameter set and from the referenced template (the referenced template has all contents commented out to ensure we are testing only the pass-through of the parameters), then the deployment succeeds, indicating that the issue is related to the parsing of the parameter string "[reference(concat(deployment().name, '-config').outputs.configuration.value)]".

Can anyone offer any insight as to whether I need to refer to output objects from deployment resources in a specific way in the context of a linked template parameter set?

1
well, what is the input that's expected. Also, I'm pretty sure comments are not allowed in templates, so I'm really interested how does that work. I'd want to take a look at both nested templates.4c74356b41
Comments are not 'allowed', but they do not prevent correct deployment. The '-config' template simply returns an 'object' in it's outputs, the structure of which is not relevant to the issue. The '-vm' template simply defines the parameters, and contains no other content. This issue is purely about the syntax for passing the output(s) of one deployment resource to another via it's parameters. It is entirely possible that this is not supported, but I can find no documentation that confirms this.Antony Gibbs
it is absolutely possible and the whole issue is with the objects you are trying to pass and what your template expects, so the nested templates are essential to fix this4c74356b41

1 Answers

2
votes

So after examining this more closely, I found that the syntax I was using was incorrect, but not reported by the parser:

"[reference(concat(deployment().name, '-config').outputs.configuration.value)]"

Should have been:

"[reference(concat(deployment().name, '-config')).outputs.configuration.value]"

Schoolboy error.