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

ElF*_*Fik 4 azure-storage azure-resource-manager azure-blob-storage azure-rm-template

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

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

我正在尝试保存 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]"
Run Code Online (Sandbox Code Playgroud)

不过,我想为其添加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 主权云,因此我不想将存储帐户名称注入“https://.blob.core.windows.net”字符串,因为每次部署存储主机也可能会发生变化

ElF*_*Fik 5

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

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

引用调用返回一个对象,如下所示:

{
   "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
}
Run Code Online (Sandbox Code Playgroud)

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

[concat(reference(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))).primaryEndpoints.blob, 'mycontainer')]
Run Code Online (Sandbox Code Playgroud)