将输出从一个arm部署资源链接模板传递到另一个

时间:2017-05-02 08:17:00

标签: json azure deployment arm-template

我正在使用一系列json ARM模板来部署Azure VM,并且在将信息从一个资源部署传递到另一个资源部署时遇到问题。

我使用blob存储中的链接模板部署两个资源,其中一个本身不进行任何部署,但返回一个填充了配置设置的对象,另一个然后将配置设置的输出作为参数传递给另一个模板:

  "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]"
    }
  }

在其上部署第一个资源并成功,输出[reference(concat(deployment().name, '-config')).outputs.configuration.value]被正确返回,并包含所有正确的信息并且格式正确。

如果我然后将第二个资源添加到混合中,则部署失败 以下错误:

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.'.

如果我从此参数集和引用的模板中删除"configuration"参数(引用的模板已注释掉所有内容以确保我们仅测试参数的传递),那么部署成功,表明该问题与解析参数字符串"[reference(concat(deployment().name, '-config').outputs.configuration.value)]"有关。

任何人都可以提供任何见解,我是否需要在链接模板参数集的上下文中以特定方式从部署资源中引用输出对象?

1 个答案:

答案 0 :(得分:1)

因此,在仔细研究之后,我发现我使用的语法不正确,但解析器没有报告:

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

应该是:

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

小学生错误。

相关问题