0
votes

I created an event grid subscription on storage account for a blob created event. I want to create the same thing using an ARM template but having trouble.

Observations-

  1. running the below template creates an event grid subscription on the resource group and not on the storage account.
  2. As per the Issue #563 and #455, providers should be used as the type. But 'providers' type is not valid in apiversion "2020-04-01-preview".
{
      "name": "[parameters('blobcreate_eventsubscription_name')]",
      "apiVersion": "2020-04-01-preview",
      "type": "Microsoft.EventGrid/eventSubscriptions",
      "dependsOn": [
      "[variables('storageAccountResourceId')]" //,
     //"[variables('functionAppResourceId')]"
      ],
     "properties": {
        // "topic": "[variables('storageAccountResourceId')]",
        "destination": {
        "endpointType": "AzureFunction",
        "properties": {
           "resourceId": "[variables('azureFunctionResourceId')]",
           "maxEventsPerBatch": 1,
           "preferredBatchSizeInKilobytes": 64
         } 
       },
       "filter": {
       "subjectBeginsWith": "[concat('/blobServices/default/containers', parameters('storageAccounts_blobname'))]",
       "subjectEndsWith": ".xml",
       "includedEventTypes": [
        "Microsoft.Storage.BlobCreated"
       ],
       "advancedFilters": []
     },
     "labels": [],
     "eventDeliverySchema": "EventGridSchema",
     "retryPolicy": {
       "maxDeliveryAttempts": "[parameters('eventgrid_maxDeliveryAttemps')]",
       "eventTimeToLiveInMinutes": "[parameters('eventgrid_eventTimeToLiveInMinutes')]"
     },
     "deadLetterDestination": {
       "endpointType": "StorageBlob",
       "properties": {
          "resourceId": "[variables('storageAccountResourceId')]",
          "blobContainerName": "[parameters('storageAccounts_deadletterblob_name')]"
        }
      }
    }
}
1

1 Answers

1
votes

here's an official example which you can use a base:

{
    "type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions",
    "name": "[concat(parameters('storageName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
    "apiVersion": "2018-01-01",
    "dependsOn": [
        "[parameters('storageName')]"
    ],
    "properties": {
        "destination": {
            "endpointType": "WebHook",
            "properties": {
                "endpointUrl": "[parameters('endpoint')]"
            }
        },
        "filter": {
            "subjectBeginsWith": "",
            "subjectEndsWith": "",
            "isSubjectCaseSensitive": false,
            "includedEventTypes": [
                "All"
            ]
        }
    }
}

notice the resourceType and name of the resource.

https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-event-grid-subscription-and-storage/azuredeploy.json