我已經使用Azure資源管理模板安裝了Azure IOThub。我需要獲得「共享訪問策略」 - 「iothubowner」的主要價值,並將其用於設置下游的另一個資源。Azure ARM - 列表鍵 - 如何獲取特定鍵的鍵值?
我能夠如下
"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"
},
獲取所有使用在天青ARM模板JSON的listkeys函數的共享訪問策略和它們各自的主鍵爲陣列/對象
.... ]
我需要知道如何過濾只的「iothu中的PrimaryKey保加利亞「政策?
我試過,但有錯誤
"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.."
}
我能夠使用數組'0'的絕對索引(因爲iothubowner總是作爲數組中的第一個進來)來獲取主鍵od iothubowner ...但它會是很高興根據共享訪問策略的名稱進行過濾,而不是索引 「IoT_hub_ownerkey1」:{ 「value」:「[listkeys(resourceId('Microsoft.Devices/IotHubs',variables('vHubName')),' 2016-02-03')。value [0] .primaryKey]「, 」type「:」string「 }, – TinkerBotFoo