0

I am trying to deploy Azure IoT device connected event subscription to Azure storage queue using ARM template and PowerShell. I have used the following template for deploying this. Also, I have read a lot of articles on Microsoft. But could not find any solution. Please help me to figure it out.

 "resources": [
    {
        "type": "Microsoft.EventGrid/eventSubscriptions",
        "name": "DeviceConnected",
        "location": "[resourceGroup().location]",
        "apiVersion": "2018-01-01",
        "dependsOn": [
          "[resourceId('Microsoft.Devices/IotHubs', variables('iotHubName'))]"
        ],
        "properties": {

          "destination": {
            "endpointType": "storagequeue",
            "properties": {
              "queueName":"device-connnection-state-queue",
              "resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]"
            }
        },

          "filter": {
            "includedEventTypes": [
              "Microsoft.Devices.DeviceConnected"
            ]
          }
        }
      }
],

The error is showing like enter image description here

Syam Kumar
  • 343
  • 5
  • 16
  • remove the `dependson` and give it another try. dependson only applies if you would like to deploy the iothub in the same arm template so ARM knows it has to deploy the iothub first. – Thomas Jun 24 '19 at 10:19
  • But we have to mention the event subscription from IoT hub. Right? If I remove dependson, how will I mention it is IoT hub event subscription? Otherwise, how will we add event subscription for existing IoT hub? – Syam Kumar Jun 24 '19 at 10:45
  • try to change the type to: `Microsoft.Devices/IotHubs/providers/eventSubscriptions` and change the name to be `[concat(variables('iotHubName'), '/Microsoft.EventGrid/', 'DeviceConnected')]` – Thomas Jun 24 '19 at 11:26

1 Answers1

1
  1. The error you're seeing is related to the dependsOn property you've specified.

    From MS documentation

    Resources that must be deployed before this resource is deployed. Resource Manager evaluates the dependencies between resources and deploys them in the correct order. When resources aren't dependent on each other, they're deployed in parallel. The value can be a comma-separated list of a resource names or resource unique identifiers. Only list resources that are deployed in this template. Resources that aren't defined in this template must already exist. Avoid adding unnecessary dependencies as they can slow your deployment and create circular dependencies. For guidance on setting dependencies, see Defining dependencies in Azure Resource Manager templates.

    So a resource that is not defined in an ARM template cannot be used in a DependsOn property.

  2. Here is the documentation related to event subscription creation:

    Microsoft.EventGrid eventSubscriptions template reference

    There are not so much samples on how to create event subscription but you can extract some part of the template from the Azure Portal:

    • Click + Event Subscription enter image description here

    • Fill in the details enter image description here

    • Click the Advanced Editor button link on the top right corner enter image description here

    • It will show you some of the details you need to create your ARM Template enter image description here

Here is how a sample ARM template can look likes:

"resources": [
    {
      "type": "Microsoft.Devices/IotHubs/providers/eventSubscriptions",
      "apiVersion": "2019-01-01",
      "name": "[concat(parameters('iotHubName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
      "location": "[resourceGroup().location]",
      "properties": {
        "topic": "[resourceId('Microsoft.Devices/IotHubs', parameters('iotHubName'))]",
        "destination": {
          "endpointType": "StorageQueue",
          "properties": {
            "resourceId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
            "queueName": "[parameters('queueName')]"
          }
        },
        "filter": {
          "includedEventTypes": [
            "Microsoft.Devices.DeviceConnected"
          ],
          "advancedFilters": []
        },
        "labels": [],
        "eventDeliverySchema": "EventGridSchema"
      }
    }
]
Thomas
  • 24,234
  • 6
  • 81
  • 125