3
votes

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?

1
I don't think it's possible to do that. The AEG model requires to create a subscription resource in the scope of the topic. What is your business case for this scenario? - Roman Kiss
We have micro services where each has its own resource group and publishes events to their custom event grid topic. We are writing a new micro service that wants to react on these events. I thought this was the entire point of event grid, seems like an enormous oversight if this is not possible - Alex
As I mentioned, the AEG subscription is coupled to the topic scope where is a source of interest. There is no an opposite way such as assigning a topic to the subscription resource, in other words, there is no central storage of subscriptions. However, your business requirements can be handled by cascading an event between the source interest and its consuming. Some concept of the AEG cascading across the boundary (tenants, resource groups, etc.) can be found in the stackoverflow.com/questions/55342241/… - Roman Kiss
@Roman Kiss Was hoping to be able to deploy AEG subscription with ARM without having to touch the publisher’s resource group, although from your comments that seems impossible to do. It not being possible is still an answer, write it as an answer I’ll mark it as the accepted solution - Alex
@Sio you can use event grid domains to achieve some decoupling as Roman Kiss suggests. Both publisher and subscriber get coupled to an event grid domain rather than each other. This is the approach we ended up taking. But you right AWS have modelled their eventing much better - Alex

1 Answers

2
votes

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.