我使用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.."
}
答案 0 :(得分:5)
以下是我从ARM模板输出'iothubowner'的主键所做的工作:
"outputs": {
"IotHubKey": {
"type": "string",
"value": "[listKeys(resourceId('Microsoft.Devices/IotHubs/Iothubkeys', variables('iotHubName'), 'iothubowner'), '2016-02-03').primaryKey]"
}
}
希望有所帮助:)