1
votes

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.

1
Could you please share a snippet of the ARM template you use to deploy a subscription against a Function ?Loul G.

1 Answers

1
votes

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"
                    }
                }
            ]
        }
    }
},