Unable to deploy diagnostic setting for Iot Hub using ARM Template

Aditya Tangirala 1 Reputation point
2021-07-29T19:58:57.43+00:00

I have tried deploying the Diagnostics settings for IotHub service using the ARM Template.
The following is the ARM Template I have used to deploy the diagnostics settings to existing iothub resource

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Devices/IotHubs/providers/diagnosticsSettings",
"apiVersion": "2021-02-01-preview",
"name": "test01-acshyd-iothub/Microsoft.Insights/test-iothub-diagnostics",
"properties": {
"name": "test-iothub-diagnostics",
"workspaceId": "/subscriptions/xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxx/resourcegroups/rg-demo/providers/microsoft.operationalinsights/workspaces/demo-loganalytics-dev",
"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
}
}
]
}
}
]
}

But it resulted in the error saying
{
"status": "Failed",
"error": {
"code": "BadRequest",
"message": ""
}
}

I have figured out the way of getting this through powershell script, Azure CLI and Azure Portal nut unable to get this through ARM template.
Could someone guide on having this through the ARM Template.

Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
391 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,466 Reputation points
    2021-07-30T06:08:07.99+00:00

    @Aditya Tangirala Welcome to Microsoft Q & A Community Forum. I have tested your template. Seems the apiVersion is incorrect. The supported api-versions are '2015-07-01, 2016-09-01, 2017-05-01-preview, 2021-05-01-preview, 2020-01-01-preview'.

    Here is the modified template.

    azuredeploy.json

    {  
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",  
        "contentVersion": "1.0.0.0",  
        "parameters": {  
            "iothubname": {  
                "type": "String"  
            },  
            "settingName": {  
                "type": "String"  
            },  
            "workspaceId": {  
                "type": "String"  
            }  
        },  
        "resources": [  
            {  
                "type": "Microsoft.Devices/IotHubs/providers/diagnosticSettings",  
                "name": "[concat(parameters('iothubname'),'/Microsoft.Insights/', parameters('settingName'))]",  
                "dependsOn": [],  
                "apiVersion": "2021-05-01-preview",  
                "properties": {  
                    "name": "[parameters('settingName')]",  
                    "workspaceId": "[parameters('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  
                            }  
                        }  
                    ]  
                }  
      
            }  
        ]  
    }  
    

    azuredeploy.parameters.json : Kindly update the parameter file with your resource names.

    {  
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",  
        "contentVersion": "1.0.0.0",  
        "parameters": {  
            "iothubname": {  
                "value": ""   
            },  
            "settingName": {  
                "value": ""   
            },  
            "workspaceId": {  
                "value": ""   
            }  
        }  
    }  
    

    Azure CLI Command : az deployment group create --name <name-of deployment> --resource-group <rgname> --template-file azuredeploy.json --parameters azuredeploy.parameters.json

    1 person found this answer helpful.