【问题标题】:ARM - How can I get the access key from a storage account to use in sql server audit settings later in the templateARM - 如何从存储帐户获取访问密钥,以便稍后在模板中用于 sql server 审核设置
【发布时间】:2020-05-20 12:41:16
【问题描述】:

无法从数组中获取单个访问键值, 我关注了这个参考https://stackoverflow.com/a/50407157/11191182

"storageAccountAccessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('StorageAccountName')), '2017-10-01').key]",

错误

语言表达式属性 'key1' 不存在,可用属性是 'keys'。'",

【问题讨论】:

  • 试试.keys[0],这取决于你使用的API版本。
  • 我添加了这个“storageAccountAccessKey”:“[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('StorageAccountName')), '2017-10-01').keys[0] ]",但它会抛出类似 { The 'parameters.properties.storageAccountAccessKey' segment in the url is invalid } I use apiVersion - 2017-10-01
  • 嗨@prachi sawant 你试过.keys[0].value,怎么样?

标签: azure-devops azure-blob-storage arm-template azure-automation azure-sql-server


【解决方案1】:

.key1 是函数 listKeys 的旧版本。现在的语法是.keys[0].value

 "StorageAccount": "[Concat('DefaultEndpointsProtocol=https;AccountName=',variables('StorageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('StorageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value)]"  

更新: 对于 .key1 语法,您可以尝试使用旧版本的 api (2015-05-01-preview)。请参考以下示例:

"accessKey": "[listKeys(variables('storageAccountid'),'2015-05-01-preview').key1]"

更多信息请参考博客Retrieve Azure Storage Key in ARM Script

【讨论】:

  • 啊,我忘了.value 位,是的,应该这样做。我也反对为这些调用使用浮动版本,因为您可能会获得不兼容的 API 的未来版本(所以.keys[0].value 变为.primaryKey 或其他东西),我想做的最后一件事是让模板停止工作没有任何变化。
  • 是的,我试过了,它工作得很好,但是如果想传递 key1 或 primarykey 而不是 keys[0].value 那么它会失败
  • 嗨@prachisawant 如果你想使用key1,你需要使用旧版本的api 2015-05-01-preview
  • 嗨@prachisawant 您是否根据上述更新指定了旧版本的api。如果它回答了您的问题,请accept above answer
猜你喜欢
  • 2016-01-18
  • 1970-01-01
  • 2018-02-09
  • 1970-01-01
  • 2019-04-06
  • 1970-01-01
  • 2021-02-16
  • 2017-01-02
  • 2021-04-06
相关资源
最近更新 更多