4

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?

Alex
  • 3,245
  • 2
  • 19
  • 17
  • 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 Oct 08 '19 at 01:10
  • 2
    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 Oct 08 '19 at 06:49
  • 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 https://stackoverflow.com/questions/55342241/handle-blob-events-from-storage-accounts-in-multiple-azure-subscriptions-in-diff – Roman Kiss Oct 08 '19 at 16:31
  • 1
    @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 Oct 08 '19 at 18:10
  • Another option for your scenario is to create an AEG event domain endpoint in the separate resource group. Your publishers (source of interest) will post the events to this event domain endpoint. Subscribers can subscribed to the event domain topic with an event handler webhook endpoint of your microservice. In other words, you can keep in full transparent your microservices such as publishers and event handlers (consumers). The logical connectivity between them is done by AEG around the event domain and in the separate resource group. – Roman Kiss Oct 08 '19 at 19:31
  • the following is a feedback link to the AEG team: https://feedback.azure.com/forums/909934-azure-event-grid – Roman Kiss Oct 08 '19 at 19:37
  • 1
    I was hoping to achieve the same - subscription in a different RG decoupled from the publisher - as I've always been frustrated you can't do it with Service Bus either. I'm not sure why it's modelled this way. I'm pretty sure AWS has always had the pub and sub decoupled for SNS and SQS. – Sio Apr 21 '20 at 15:22
  • 1
    @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 Apr 21 '20 at 15:48
  • Thanks @Alex, I'll look into domains. – Sio Apr 22 '20 at 08:14
  • Feedback added. Please upvote! https://feedback.azure.com/forums/909934-azure-event-grid/suggestions/40903996-allow-event-grid-topics-and-subscriptions-to-be-in – Mike Pennington Jul 14 '20 at 15:39

1 Answers1

2

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.

  • 1
    Using an Event Grid Domain in a separate resource group rather than individual topics can make the management more bearable. A single event grid domain resource can be used for all your topics and subscriptions – Alex Oct 29 '20 at 08:56
  • 1
    Is this still applying in 2022? What a big limitation by Microsoft – Oliver Nilsen Sep 21 '22 at 10:27