Search code examples
azure-eventgrid

Azure Event Grid Subscriptions on custom topic in different resource group


I am trying to subscribe to a custom event grid topic that exists on a different resource group. For example if I have a custom event grid topic my-custom-topic in a resource group publisher-group. How do I create an event grid subscription to my topic from within the resource group subscriber-group?

The following ARM template only works if the my-custom-topic is in the same resource group that I am applying the template too

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "eventGridSubscriptionName": {
            "type": "String",
            "metadata": {
                "description": "The name of the Event Grid custom topic's subscription."
            }
        },
        "location": {
            "defaultValue": "[resourceGroup().location]",
            "type": "String",
            "metadata": {
                "description": "The location in which the Event Grid resources should be deployed."
            }
        }
    },
    "resources": [
        {
            "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
            "apiVersion": "2018-01-01",
            "name": "[concat('my-custom-topic', '/Microsoft.EventGrid/', parameters('eventGridSubscriptionName'))]",
            "location": "[parameters('location')]",
            "properties": {
                "destination": {
                    "endpointType": "EventHub",
                    "properties": {
                        "resourceId": "..."
                    }
                },
                "filter": {
                    "includedEventTypes": [
                        "All"
                    ]
                }
            }
        }
    ]
}

If I change name to be a the full path of the topic (e.g. subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx/resourceGroups/publisher-group/providers/Microsoft.EventGrid/topics/my-custom-topic) then the template complains I have too many segments

I would have thought this was a very common use case having topics and subscriptions in different resource groups but I am unable to find concrete examples of this

How do I create an ARM template to subscribe to an event grid topic on a different resource group?


Solution

  • This isn't possible - Event Grid Topics and Subscriptions have to be in the same resource group.

    I would suggest creating a separate resource group just for containing your Event Grid Topic and all of it's Subscriptions.

    Logically you shouldn't think of a single event publisher as owning the Event Grid Topic it publishes to - rather think of a Topic as a shared resource which many publishers and subscribers depend on.