Azure ARM - 列出键 - 如何获取特定键的键值?

Azure ARM - List keys - How to fetch key value of a specific key?

我已经使用 Azure 资源管理模板设置了 Azure IOThub。我需要获取 "shared access policy" - 'iothubowner' 的主键值并将其用于下游另一个资源的设置。

我能够使用 Azure ARM 模板中的 listkeys 函数获取所有共享访问策略及其各自的主键作为数组/对象 json,如下所示

"outputs": {
    "IoT_hub_ownerkey1": {
      "value": "[listkeys(resourceId('Microsoft.Devices/IotHubs',variables('vHubName')),'2016-02-03').value]",
      "type": "array"
    }
  }

结果是

      Name             Type                       Value     
  ===============  =========================  ==========
    ioT_hub_ownerkey1  Array                      [
    {
      "keyName": "iothubowner",
      "primaryKey": "mKAQTt9U5XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "secondaryKey": "DpFgimzXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "rights": "RegistryWrite, ServiceConnect, DeviceConnect"
    },
    {
      "keyName": "service",
      "primaryKey": "hrsK7laMIXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "secondaryKey": "omm3RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "rights": "ServiceConnect"
    },
    {
      "keyName": "device",
      "primaryKey": "sfE9QbhLDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "secondaryKey": "v5Oyw3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "rights": "DeviceConnect"
    },

..... ]

我需要知道如何只过滤 "iothubowner" 策略的主键?

我试过了但是出错了

"IoT_hub_ownerkey2": {
  "value": "[listkeys(resourceId('Microsoft.Devices/IotHubs',variables('vHubName')),'2016-02-03').value.keyName['iothubowner'].primaryKey]",
  "type": "string"
}

错误

    {
      "code": "DeploymentOutputEvaluationFailed",
      "target": "IoT_hub_ownerkey2",
      "message": "The template output 'IoT_hub_ownerkey2' is not valid: Template language expression property 'keyName' has an invalid array index. Please 
see https://aka.ms/arm-template-expressions for usage details.."
    }

这是我从我的 ARM 模板输出 'iothubowner' 主键的操作:

"outputs": { "IotHubKey": { "type": "string", "value": "[listKeys(resourceId('Microsoft.Devices/IotHubs/Iothubkeys', variables('iotHubName'), 'iothubowner'), '2016-02-03').primaryKey]" } }

希望对您有所帮助:)