Vladislav
Vladislav

Reputation: 2992

Azure template deployment for IoT Hub and diagnostics settings does not work

I'm using Azure RM Template deployments with a Visual Studio 2017 Resource Group project to deploy IoTHub instance with diagnostics settings in Log Analytics.

Deploying IoTHub alone is successful, the problem is with deployment of the Diagnostics Settings template.

I'm following the instructions for deploying Diagnostics Settings as Non-Compute resource template

The strange error that I receive is the following:

Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template resource 'Microsoft.Insights/BasicDiagnostics' for type 'providers/diagnosticSettings' at line '69' and column '9' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name.

Why does it fail like this, even though I follow the documentation with the provided example?

Here are my template definitions:

  "resources": [
    {
      "type": "Microsoft.Devices/IotHubs",
      "sku": {
        "name": "[parameters('sku.name')]",
        "capacity": "[parameters('sku.units')]"
      },
      "name": "[parameters('iothubname')]",
      "apiVersion": "2018-04-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "eventHubEndpoints": {
          "events": {
            "retentionTimeInDays": "[parameters('endpoints.events.retention')]",
            "partitionCount": "[parameters('endpoints.events.partitions')]"
          },
          "operationsMonitoringEvents": {
            "retentionTimeInDays": "[parameters('endpoints.operationsMonitoringEvents.retention')]",
            "partitionCount": "[parameters('endpoints.operationsMonitoringEvents.partitions')]"
          }
        },
        "features": "[parameters('features')]"
      }
    },
    {
      "type": "providers/diagnosticSettings",
      "name": "[concat('Microsoft.Insights/', parameters('iotHub.diagnostics.settingName'))]",
      "dependsOn": [
        "[resourceId('Microsoft.Devices/IoTHubs', parameters('iothubname'))]"
      ],
      "apiVersion": "2017-05-01-preview",
      "properties": {
        "name": "[parameters('iotHub.diagnostics.settingName')]",
        "workspaceId": "[parameters('iotHub.diagnostics.workspaceId')]",
        "logs": [
          {
            "category": "Connections",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          },
          {
            "category": "Configurations",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          },
          {
            "category": "D2CTwinOperations",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          },
          {
            "category": "C2DTwinOperations",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          }
        ],
        "metrics": [
          {
            "category": "AllMetrics",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          }
        ]
      }
    }
  ]

Any help much appreciated!

Upvotes: 1

Views: 454

Answers (1)

4c74356b41
4c74356b41

Reputation: 72201

this needs to be a sub resource of the IOT hub, not a separate resource.

{
    "type": "Microsoft.Devices/IotHubs",
    "sku": {
        "name": "[parameters('sku.name')]",
        "capacity": "[parameters('sku.units')]"
    },
    "name": "[parameters('iothubname')]",
    "apiVersion": "2018-04-01",
    "location": "[resourceGroup().location]",
    "properties": {
        xxx
    },
    "features": "[parameters('features')]",
    "resources": [
        {
            "type": "providers/diagnosticsSettings",
            xxx
        }
    ]
}

},

Upvotes: 1

Related Questions