0

via portal, I can define an Event Subscription in the Storage Account, at the End I have such a view in the portal: enter image description here

Now I would like to do the same with ARM-Template, I have the following Code:

{
  "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
  "name": "[concat(variables('StorageAccountName'),'/Microsoft.EventGrid/',variables('EventGridName'))]",
  "location": "[parameters('region')]",
  "apiVersion": "2018-01-01",
  "dependsOn": [ "[resourceId('Microsoft.Web/sites', variables('AzureFunction'))]" ],
  "properties": {
    "topic": "[concat('Microsoft.EventGrid/topics/',variables('StorageAccountName'))]",
    "destination": {
      "endpointType": "WebHook",
      "properties": {
        "topics": "[variables('StorageAccountName')]",
        "endpointUrl": "[concat('https://', variables('AzureFunction'),'.azurewebsites.net/admin/extensions/EventGridExtensionConfig')]"
      }
    }

  }
}

after running this code, I get the following error:

Resource Microsoft.EventGrid/topics/providers/eventSubscriptions 'xxxx0prod0sac0xx0we/Microsoft.EventGrid/xxxx-prod-eg-dz-we' failed with message '{
   "error": {
     "code": "ResourceNotFound",
     "message": "The Resource 'Microsoft.EventGrid/topics/xxxx0prod0sac0xx0we' under resource group 'xxxx' was not found."
   }
 }'

Do you have any idea, what should I do to solve this problem?

Kaja
  • 2,962
  • 18
  • 63
  • 99
  • It may caused by the wrong parameters or variables in your template (probably the variables in "name"), so could you please share the whole arm template of your deployment(including the parameters and variables) ? – Hury Shen Sep 05 '19 at 04:24

1 Answers1

0

@Kaja, Please use the below ARM template to create an Event Subscription in the Storage Account:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageName": {
      "type": "string",
      "defaultValue": "[concat('storage', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Provide a unique name for the Blob Storage account."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Provide a location for the Blob Storage account that supports Event Grid."
      }
    },
    "eventSubName": {
      "type": "string",
      "defaultValue": "subToStorage",
      "metadata": {
        "description": "Provide a name for the Event Grid subscription."
      }
    },
    "endpoint": {
      "type": "string",
      "metadata": {
        "description": "Provide the URL for the WebHook to receive events. Create your own endpoint for events."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions",
      "name": "[concat(parameters('storageName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
      "apiVersion": "2018-01-01",
      "properties": {
        "destination": {
          "endpointType": "WebHook",
          "properties": {
            "endpointUrl": "[parameters('endpoint')]"
          }
        },
        "filter": {
          "subjectBeginsWith": "",
          "subjectEndsWith": "",
          "isSubjectCaseSensitive": false,
          "includedEventTypes": [
            "All"
          ]
        }
      }
    }
  ]
}

Reference: https://github.com/Azure/azure-quickstart-templates/blob/master/101-event-grid-subscription-and-storage/azuredeploy.json

AmanGarg-MSFT
  • 1,123
  • 6
  • 10