无法在链接的ARM模板之间传递安全值

时间:2018-04-16 10:52:14

标签: azure azure-resource-manager arm-template azure-template

我正在尝试输出在一个链接模板中创建的秘密,并将其作为另一个参数引用。 测试场景:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "templateBaseUrl": {
      "type": "string"
    }
  },
  "variables": {
    "deployment1url": "[concat(parameters('templateBaseUrl'), '/deployment1.json')]",
    "deployment2url": "[concat(parameters('templateBaseUrl'), '/deployment2.json')]"
  },
  "resources": [
    {
      "apiVersion": "2017-08-01",
      "name": "deployment1",
      "dependsOn": [],
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[variables('deployment1url')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {}
      }
    },
    {
      "apiVersion": "2017-08-01",
      "name": "deployment2",
      "dependsOn": [],
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[variables('deployment2url')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "testInput2": {
            "value": "[reference('deployment1').outputs.testOutput1.value]"
          }
        }
      }
    }
  ],
  "outputs": {}
}

Deployment1:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    },
    "resources": [],
    "outputs": {
        "testOutput1": {
            "type": "securestring",
            "value": "thisisapassword"
        }
    }
}

Deployment2:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "testInput2": {
            "type": "securestring"
        }
    },
    "resources": [],
    "outputs": {}
}

运行此方案会引发错误 “无法处理资源的模板语言表达式 '/subscriptions//resourceGroups/testrg1/providers/Microsoft.Resources/deployments/deployment2'在第34行和第9列。 '语言表达式属性'value'不存在,可用属性为'type'。'“

如果我将引用参数更改为

,那么在securestring输出上'.value'不起作用
"testInput2": {
                "value": "[reference('deployment1').outputs.testOutput1]"
              }

错误更改为“部署模板验证失败:”第5行和第23行的模板参数“testInput2”的提供值无效。'。'

有可能实现我的目标吗?

提前致谢

1 个答案:

答案 0 :(得分:2)

我认为在部署之间传递secureStrings的唯一方法是使用KeyVault引用。 secureString输出不是很有用,因为ARM在部署级别屏蔽了安全字符串。

那有帮助吗?