1

我已经使用 Azure 资源管理模板设置了 Azure IOThub。我需要获取“共享访问策略” - 'iothubowner' 的主键值并将其用于设置下游的另一个资源。

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

"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.."
    }
4

1 回答 1

6

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

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

希望能帮助到你 :)

于 2016-08-31T00:46:16.177 回答