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

标签 json azure deployment azure-rm-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)]".

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

最佳答案

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

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

应该是:

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

小学生的错误。

关于json - 将一个arm部署资源链接模板的输出传递到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43733211/

相关文章:

javascript - 将结果从 .getJSON() 传递到另一个函数导致未定义

.net - 未采用 Google Site Verification API .NET 重定向 uri

azure - JavaScript 无法在内置用户策略注册页面中的 Azure AD B2C 上运行

ruby-on-rails - ActionView::MissingTemplate

java - 请求的资源在 Servlet、Tomcat7 中不可用

java - Tomcat JDBCRealm 身份验证在部署后不起作用

Mysql+json格式化

php - 在 php 中创建嵌套的 JSON 对象?

c# - 是否可以对函数应用程序和 Web 应用程序使用单个 Application Insights 实例

azure 。如何使用 ARM 模板从托管镜像部署 VM