Tin*_*Foo 1 azure azure-sdk-.net azure-resource-manager azure-iot-hub azure-resource-group
我使用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"
}
}
Run Code Online (Sandbox Code Playgroud)
结果
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"
},
Run Code Online (Sandbox Code Playgroud)
....]
我需要知道如何只过滤"iothubowner"政策的主键?
我试过这个,但得到了错误
"IoT_hub_ownerkey2": {
"value": "[listkeys(resourceId('Microsoft.Devices/IotHubs',variables('vHubName')),'2016-02-03').value.keyName['iothubowner'].primaryKey]",
"type": "string"
}
Run Code Online (Sandbox Code Playgroud)
错误
{
"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.."
}
Run Code Online (Sandbox Code Playgroud)
以下是我从ARM模板输出'iothubowner'主键的操作:
"outputs": {
"IotHubKey": {
"type": "string",
"value": "[listKeys(resourceId('Microsoft.Devices/IotHubs/Iothubkeys', variables('iotHubName'), 'iothubowner'), '2016-02-03').primaryKey]"
}
}
希望能帮助到你 :)
| 归档时间: |
|
| 查看次数: |
1840 次 |
| 最近记录: |