如何获取 ARM 模板中 Azure 存储帐户的容器的路径

How can I get the path to an Azure Storage account's Container in ARM template

问题:如果可以访问存储 account/container 资源,我如何在我的 ARM 模板中为容器生成 URL?

我有一个 Azure 存储帐户和 blob 容器,我正在通过 ARM 模板部署。

我正在尝试保存 SAS URI 以写入我的 keyvault 中的 blob 存储。

我已经能够像这样取消引用 SAS URI 查询参数:

  "variables": {
    "accountSasFunctionValues": {
      "signedServices": "bqt",
      "signedPermission": "rlacup",
      "signedResourceTypes": "oc",
      "signedExpiry": "2050-01-01T00:00:00Z"
    }
  },
.
.
.
... "value": "[listAccountSas(parameters('storageAccountName'), '2018-02-01', variables('accountSasFunctionValues')).accountSasToken]"

但是我想在这个 value 前面加上容器的路径,这样我就可以用我的有效负载在不同服务中的 URI 上调用 "PUT" 并上传它。

类似于 "value": "[concat(getUri(concat('Microsoft.Storage/storageAccounts/blobServices/containers/', parameters('storageAccountName'), '/default/mycontainer')), '?', listAccountSas(parameters('storageAccountName'), '2018-02-01', variables('accountSasFunctionValues')).accountSasToken]" - 注意 uri 以 sas uri 查询参数为前缀。

我们可能需要部署到不同的 Azure Sovereign Cloud,所以我不想将存储帐户名称注入到 "https://.blob.core.windows.net" 字符串中,因为存储主机也可能随部署而改变

我看到 reference(...) expression 可以用来获取一些数据。

"outputs": {
    "BlobUri": {
        "value": "[reference(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))).primaryEndpoints.blob]",
        "type" : "string"
    }
}

引用调用returns一个像这样的对象:

{
   "creationTime": "2017-10-09T18:55:40.5863736Z",
   "primaryEndpoints": {
     "blob": "https://examplestorage.blob.core.windows.net/",
     "file": "https://examplestorage.file.core.windows.net/",
     "queue": "https://examplestorage.queue.core.windows.net/",
     "table": "https://examplestorage.table.core.windows.net/"
   },
   "primaryLocation": "southcentralus",
   "provisioningState": "Succeeded",
   "statusOfPrimary": "available",
   "supportsHttpsTrafficOnly": false
}

这让我获得了 blob 存储帐户的主要端点。然后我可以通过以下方式获取容器端点:

[concat(reference(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))).primaryEndpoints.blob, 'mycontainer')]