How to use listkeys function in an ARM Template with Event Hub

Viewed 7491

I have an event hub that looks like this: enter image description here

enter image description here

enter image description here

enter image description here

I have successfully done it for service bus, but only for the high level RootManageSharedAccessKey.

However with Event Hub I want the primary connection string for the SendOnly shared access policy.

I have tried many combinations but I when I deploy the deployment cant find the SendOnly shared access policy.

Here is the json for my SendOnly shared access policy.

enter image description here

Any help will be greatly appreciated.

3 Answers

The final working ARM template code was:

[listkeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('ehub').name, parameters('eventhubs_myaccountevents_name'), 'SendOnly'), parameters('eventhubs_api_version')).primaryConnectionString]

Note that instead of this:

Microsoft.Eventhub/namespaces/authorizationRules

I had to use this:

Microsoft.EventHub/namespaces/eventhubs/authorizationRules

Here is the sample I used: https://github.com/pascalnaber/EnterpriseARMTemplates/blob/6babc4d3e65f10f999bb144a1d616ccb2a085e9d/templates/resources/Microsoft.Eventhub/azuredeploy.json

use this to get the connection string:

"[listkeys(resourceId('Microsoft.Eventhub/namespaces/authorizationRules',
  parameters('name'), 'RootManageSharedAccessKey'),
  '2017-04-01').primaryConnectionString]"

you cannot split it across lines, i've done that for sake of readibility

This is how I solved it (including creating the authorization rule):

Define the variables:

...
"variables": {
    "eventHubNamespaceName": "myehubns",
    "eventHubName": "myehub",
    "eventhubSendAuthorizationRuleName": "SendOnly",
    "eventHubSendRuleId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('eventHubNamespaceName'),variables('eventHubName'), variables('eventhubSendAuthorizationRuleName'))]"
}

Create the Authorization Rule:

...
"resources": [{
        "apiVersion": "2017-04-01",
        "name": "[variables('eventhubSendAuthorizationRuleName')]",
        "type": "authorizationRules",
        "dependsOn": [
            "[concat('Microsoft.EventHub/namespaces/', variables('eventHubNamespaceName'),'/eventhubs/',variables('eventHubName'))]"
        ],
        "properties": {
            "rights": [
                "Send"
            ]
        }
    }
]

Retrieve the primary Connection String of the previous created rule:

"EventHubConnectionstring": "[listkeys(variables('eventHubSendRuleId'), '2017-04-01').primaryConnectionString]"
Related