4

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.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
RuSs
  • 1,725
  • 1
  • 29
  • 47

3 Answers3

13

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

RuSs
  • 1,725
  • 1
  • 29
  • 47
7

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

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • But that's the root connection string. I need the send only – RuSs Nov 19 '17 at 10:58
  • 1
    replace `'RootManageSharedAccessKey'` with `'SendOnly'`? – 4c74356b41 Nov 19 '17 at 11:37
  • I also had to add another resourceid section in between namespaces and authorizationRules: [listkeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('ehub').name, parameters('eventhubs_myaccountevents_name'), 'SendOnly'), parameters('eventhubs_api_version')).primaryConnectionString] – RuSs Nov 19 '17 at 22:15
  • well, you could at least upvote my answer, as its the right one, technically ;) – 4c74356b41 Nov 20 '17 at 06:23
  • Sorry man I have done that now. Are you saying yours works as well if I just replace RootConnectionShar.... If so why do they both work? – RuSs Nov 20 '17 at 06:42
  • interesting, i wasnt awake enough ;) I didnt test it with `'SendOnly'`, tbh, I assumed it would work like that, but looking at your answer now, it might be that it wont work. – 4c74356b41 Nov 20 '17 at 07:36
  • I'll try your suggestion just for fun tomorrow – RuSs Nov 20 '17 at 07:37
  • I tried youway, with just replacing the RootManageSharedAccessKey with SendOnly and that failed. Then I added /eventhubs in here: / Microsoft.Eventhub/namespaces/eventhubs/authorizationRules and The event hub name in as well so the final result was this: [listkeys(resourceId('Microsoft.Eventhub/namespaces/eventhubs/authorizationRules', variables('ehub').name, parameters('eventhubs_myaccountevents_name'), 'SendOnly'), parameters('eventhubs_api_version')).primaryConnectionString] Which now works. So im afraid your way doesn't work. Russ – RuSs Nov 21 '17 at 00:45
3

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]"
Community
  • 1
  • 1
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172