Jan_V
Jan_V

Reputation: 4406

Creating storage queue subscription to custom Event Grid Topic via ARM

I'm trying to set up an Event Grid subscription to my Storage Queue from a custom topic.

This is easy to do when navigating in the portal, but I'm failing to create the appropriate ARM template for this. After having searched and tried out a lot, I've come up with the following piece of template.

{
    "name": "MyCustomTopicName/Microsoft.EventGrid/MySubscriptionName",
    "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
    "location": "[resourceGroup().location]",
    "apiVersion": "2019-06-01",
    "properties": {
        "destination": {
            "endpointType": "StorageQueue",
            "properties": {
                "resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('theNameOfMyStorageAccount'))]",
                "queueName": "[variables('theNameOfMyQueue')]"
            }
        },
        "filter": {
            "advancedFilters": []
        },
        "labels": [],
        "eventDeliverySchema": "EventGridSchema"
    }
}

This looks rather OK to me but fails because the Event Grid topic isn't in the resource group to which I'm deploying the template.

Deployment failed. Correlation ID: [guid]. {
  "error": {
    "code": "ResourceNotFound",
    "message": "The Resource 'Microsoft.EventGrid/topics/MyCustomTopicName' under resource group 'TheResourceGroupTheStorageAccountIsIn' was not found."
  }
}

I'm deploying the complete ARM template to TheResourceGroupTheStorageAccountIsIn. The MyCustomTopicName topic is in a resource group where we place the custom topics, so all services can use it.

I've tried using the full identifier (resource id) of the custom topic, but this isn't valid. Ideas?

PS: I'm using a similar template for creating a subscription to an Azure Function, which does work properly. The main difference over there is the destination block, which makes sense.

Upvotes: 1

Views: 451

Answers (1)

4c74356b41
4c74356b41

Reputation: 72171

If I'm reading this right you just need to use a nested deployment and target the resource group where the topic is in:

{
    "apiVersion": "2017-05-10",
    "name": "nestedTemplate",
    "type": "Microsoft.Resources/deployments",
    "resourceGroup": "your_topic_resource_roup",
    "properties": {
        "mode": "Incremental",
        "template": {
            "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "parameters": {},
            "variables": {},
            "resources": [
                {
                    "name": "MyCustomTopicName/Microsoft.EventGrid/MySubscriptionName",
                    "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
                    "location": "[resourceGroup().location]",
                    "apiVersion": "2019-06-01",
                    "properties": {
                        "destination": {
                            "endpointType": "StorageQueue",
                            "properties": {
                                "resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('theNameOfMyStorageAccount'))]",
                                "queueName": "[variables('theNameOfMyQueue')]"
                            }
                        },
                        "filter": {
                            "advancedFilters": []
                        },
                        "labels": [],
                        "eventDeliverySchema": "EventGridSchema"
                    }
                }
            ]
        }
    }
},

Upvotes: 1

Related Questions