通过 ARM 模板在本地部署上使用 [deployment().properties.templateLink.uri]

Use [deployment().properties.templateLink.uri] on local deployments through ARM templates

当我尝试使用 ARM linked Template 时...

    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2018-05-01",
      "name": "[concat('EventHubLinkedTemplate-', parameters('eventHubNames')[copyindex('eventHubNameIterator')])]",
      "copy": {
        "name": "eventHubNameIterator",
        "count": "[length(parameters('eventHubNames'))]"
      },
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[uri(deployment().properties.templateLink.uri, '/eventHub/template.json')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "consumerGroups": "[parameters('consumerGroups')]",
          "eventHubName": "[concat(variables('eventHubNamespace'), '/', parameters('eventHubNames'))]"
        }
      }
    }

...从父 ARM 模板,使用 Visual Studio 2019 ARM 项目的部署选项,部署在下一条消息中失败:

07:48:12 - Resource Microsoft.Resources/deployments 'EventHubLinkedTemplate-test' failed with message '{
  "error": {
  "code": "InvalidTemplate",
  "message": "Unable to process template language expressions for resource '/subscriptions/********-****-****-****-************/resourceGroups/*****/providers/Microsoft.Resources/deployments/EventHubLinkedTemplate-test' at line '127' and column '9'. 'The language expression property 'templateLink' doesn't exist, available properties are 'template, templateHash, parameters, mode, provisioningState'.'",
    "additionalInfo": [
      {
        "type": "TemplateViolation",
        "info": {
          "lineNumber": 127,
          "positionNumber": 9,
          "snippet": ""
        }
      }
    ]
  }
}'

有谁知道通过 ARM 模板在本地部署中使用 [deployment().properties.templateLink.uri] 的方法吗?

据我在文档中找到的,似乎还不受支持...

不,这是不可能的,因为要做到这一点,您必须上传模板(否则,您将如何获得 link??)。

一个简单的解决方法是使用一个 powershell 脚本来上传所有内容并开始部署。使用 Visual Studio 进行 ARM 模板开发并不是最好的体验。

不,不可能。

正如 official article 所说:

The templateLink property is only returned when linking to a remote template with a URL. If you're using a local template, that property isn't available.