azure-resource-manager - Azure ARM 模板 - 如何将链接模板的输出变量作为参数传递给另一个模板?

标签 azure-resource-manager arm-template

假设我们有 2 个链接的 arm 模板及其关联的 *.params.json 文件:

  1. createAppServiceTemplate.json
  2. createAppServiceTemplate.params.json
  3. createSqlDbTemplate.json
  4. createSqlDbTemplate.params.json

第二个模板 createSqlDbTemplate.json 有输出:

 "outputs": {
        "connectionString": {
            "type": "string",
            "value": "[concat('Database=', parameters('databaseName'), ';Server=', reference(resourceId('Microsoft.DBforPostgreSQL/servers',parameters('serverName')), '2017-12-01').fullyQualifiedDomainName, ';User Id=', parameters('administratorLogin'),'@', parameters('serverName'),';Password=', parameters('administratorPassword'))]"
        }
    }

我不想提取此输出变量并将其作为参数传递给 createAppServiceTemplate.params.json

我已尝试将此添加到我的:

"parameters": {
    "usersDbConnectionString": {
          "value": "[reference('createSqlDbTemplate').outputs.connectionString.value]"
    }
 }

但我认为参数不能计算表达式?我怎样才能实现所需的行为?

最佳答案

假设您有下面链接的 createSqlServerTemplate.json 模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {},
  "resources": [],
  "outputs": {
    "greetingMessage": {
      "value": "Hello World",
      "type" : "string"
    }
  }
}

主模板部署链接模板并获取返回值。请注意,它按名称引用部署资源,并使用链接模板返回的属性名称。

main-template.json:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-10-01",
      "name": "createAppServiceTemplate",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[uri(deployment().properties.templateLink.uri, 'createAppServiceTemplate.json')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
           "userDbConnectionString: {
              value: "[reference('createSqlServerTemplate').outputs.greetingMessage.value]"
           }
        }
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-10-01",
      "name": "createSqlServerTemplate",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[uri(deployment().properties.templateLink.uri, 'createSqlServerTemplate.json')]",
          "contentVersion": "1.0.0.0"
        }
      }
    }
  ]
}

Reference

关于azure-resource-manager - Azure ARM 模板 - 如何将链接模板的输出变量作为参数传递给另一个模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63358431/

相关文章:

arm-template - Azure ARM uniqueString 函数模拟

powershell - 无法通过 Powershell 在 ARM 模板中传递数组类型参数

具有策略规则收集循环的 Azure 防火墙

azure - ARM 模板 key 保管库访问策略到组而不是身份原则

Azure 对 microsoft.aadiam/diagnosticSettings/write 的权限

azure-devops - 将 secureObject 数组作为 VSTS 变量传递

powershell - 通过脚本设置管道变量时,Azure DevOps 是否删除引号?

azure-logic-apps - 对于使用已存在且已连接的 OAuth 的 API 连接,逻辑应用程序 ARM 部署失败

azure-web-app-service - 如何输出通过 ARM 模板部署的应用服务的 IP 地址

Azure 角色分配 - BadRequestFormat