@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