Reputation: 21
Hello Stackoverflow Community,
I have a problem with Microsoft Azure Provisioning, I am trying to access SharedAccessPolicyKeys for Resources like IoT-Hubs or Event-Hubs. I am trying this with listKeys function and output these inside the template JSON file:
"outputs": {
"hubKeys": {
"value": "[listKeys(resourceId('Microsoft.Devices/IotHubs', parameters('hubName')), '2016-02-03')]",
"type": "object"
}
}
When I output the returned Object in Windows Powershell it looks like this:
Type : Array
IsReadOnly : False
HasValues : True
First : {keyName, primaryKey, secondaryKey, rights}
Last : {keyName, primaryKey, secondaryKey, rights}
Count : 5
Parent : {{
"keyName": "iothubowner",
"primaryKey": "dZVFGkIysIgVRKjxlZsCWdk6KGa4rpBFlY6BOLmaiD8=",
"secondaryKey": "HtRYETAdgja/TBSS3sVTshKaGzZWMLbZC6GR60emSV4=",
"rights": "RegistryWrite, ServiceConnect, DeviceConnect"
} {
"keyName": "service",
"primaryKey": "DGOujP2tBTiTTdKxukTx7umeYFFlDEhoih7fb0tP3i8=",
"secondaryKey": "B+6j1nfEc59GAeJQNakNKolTBoR9kc5W+TUNzRXmDpc=",
"rights": "ServiceConnect"
} {
"keyName": "device",
"primaryKey": "qxmRJVH0yVhSkLEz8JaHhtDJaDofpw4SEKkZNlBwp7c=",
"secondaryKey": "RhUuME9EnnUsE2sixswaiTofKsVVfCQNIllwkHgY/8A=",
"rights": "DeviceConnect"
} {
"keyName": "registryRead",
"primaryKey": "pEpHrL4amd9+7pvl6uCiYHL3rZhxV76tZ1P9bERO6Xc=",
"secondaryKey": "6h4UBKd4WPkdpUfl0Hi3G5YKgB3LmtDMbgXDYx3eKrk=",
"rights": "RegistryRead"
} {
"keyName": "registryReadWrite",
"primaryKey": "HpCxKVa1686A8vOfNVBUzYSe2YJmKIwwAzxUh5DokuY=",
"secondaryKey": "PGeYYID9y6cClqGD1rl4koLNySc7kOGK6VuNlBiwqmo=",
"rights": "RegistryWrite"
}}
Root : {value}
Next :
Previous :
Path : value
LineNumber : 0
LinePosition : 0
AllowNew : True
AllowEdit : True
AllowRemove : True
SupportsChangeNotification : True
SupportsSearching : False
SupportsSorting : False
IsSorted : False
SortProperty :
SortDirection : Ascending
IsFixedSize : False
SyncRoot : System.Object
IsSynchronized : False
My Question: Can anyone tell me how to access the "primaryKey" in the different "keyName" Objects? In particular I need the PrimaryKey for "service".
I can print the Object with
$Key = New-AzureRmResourceGroupDeployment (deleted parameters for this post)
Write-Output $Key.Outputs.hubKeys
I already tried things like $Key.Outputs.hubKeys.value.Parents.values.... and countless other ways. Does anyone know how to get the Value?
Thanks, Arno
Upvotes: 2
Views: 599
Reputation: 2331
The sample here illustrates one way to achieve this. The ARM template creates an IoT Hub and and Azure Stream Analytics job that connects to the hub using the generated key values.
These snippets summarize the key pieces:
/* Create IoT Hub */
{
"apiVersion": "2016-02-03",
"type": "Microsoft.Devices/IotHubs",
"name": "[variables('iotHubName')]",
"location": "[resourceGroup().location]",
"sku": "[parameters('iotHubSku')]"
},
/* Part of the ASA definition */
"datasource": {
"type": "Microsoft.Devices/IotHubs",
"properties": {
"iotHubNamespace": "[variables('iotHubName')]",
"sharedAccessPolicyName": "[variables('iotHubKeyName')]",
"sharedAccessPolicyKey": "[listKeys(resourceId('Microsoft.Devices/IotHubs/Iothubkeys', variables('iotHubName'), variables('iotHubKeyName')), '2016-02-03').primaryKey]",
"consumerGroupName": "[variables('archiveJobConsumerGroupName')]"
}
}
Upvotes: 1