2

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

{
  "$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": {}
}

部署1:

{
    "$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"
        }
    }
}

部署2:

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

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

因此,如果我将引用参数更改为,安全字符串输出上的“.value”将不起作用

"testInput2": {
                "value": "[reference('deployment1').outputs.testOutput1]"
              }

the errors changes to 'Deployment template validation failed: 'The provided value for the template parameter 'testInput2' at line '5' and column '23' is not valid.'.'

Is it possible to achieve what I am doing?

Thanks in advance

4

1 回答 1

5

I think the only way to pass secureStrings across deployments is using a KeyVault reference. The secureString output isn't very useful in that securestrings are masked by ARM at the deployment level.

That help?

于 2018-04-17T14:58:24.467 回答