Azure ARM - 列表键 - 如何获取特定键的键值?
问题描述:
我已经使用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.."
}
答
这里是我做过什么,输出的主键从我的手臂模板 'iothubowner':
"outputs": { "IotHubKey": { "type": "string", "value": "[listKeys(resourceId('Microsoft.Devices/IotHubs/Iothubkeys', variables('iotHubName'), 'iothubowner'), '2016-02-03').primaryKey]" } }
希望它有助于:)
+0
Thankyou @MattWazEre这适用于我 – TinkerBotFoo
我能够使用数组'0'的绝对索引(因为iothubowner总是作为数组中的第一个进来)来获取主键od iothubowner ...但它会是很高兴根据共享访问策略的名称进行过滤,而不是索引 “IoT_hub_ownerkey1”:{ “value”:“[listkeys(resourceId('Microsoft.Devices/IotHubs',variables('vHubName')),' 2016-02-03')。value [0] .primaryKey]“, ”type“:”string“ }, – TinkerBotFoo