title: How to create Activity logs diagnostic setting for Azure resources using ARM template
body: <p>We are referring this documentation <a href="https://docs.microsoft.com/en-us/azure/azure-monitor/platform/diagnostic-settings-template" rel="nofollow noreferrer">here</a> which talks about <em>Creating diagnostic setting in Azure using a Resource Manager template</em>.</p>
  
  <p>We have managed to provision resources with ARM template along with diagnostic setting for resource logs, however snippet in the documentation to enable the <a href="https://docs.microsoft.com/en-us/azure/azure-monitor/platform/diagnostic-settings-template#activity-log" rel="nofollow noreferrer">activity logs</a> diagnostic setting does not seem to work as the template deployment command (new-azresourcegroupdeployment) returns the Bad request error.</p>
  
  <blockquote>
    <p>New-AzResourceGroupDeployment : Resource Microsoft.Insights/diagnosticSettings 'test-vnet' failed with message '{
      "Code": "BadRequest",
      "Message": ""
    }'</p>
  </blockquote>
  
  <p>Here is the template (trimmed some code to avoid noise)</p>
  
  <pre><code>{  
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
     ...
  },
  "variables": {
      ...
  },
  "resources": [
      {
          "apiVersion": "2018-08-01",
          "type": "Microsoft.Network/virtualNetworks",
          "name": "[parameters('virtualNetworkName')]",
          "location": "[parameters('resourceLocation')]",
          "properties": {
              "addressSpace": {
                  "addressPrefixes": [
                      "[parameters('addressPrefix')]"
                  ]
              },
              "subnets": "[parameters('subnets')]",
              "dhcpOptions": {
                  "dnsServers": "[parameters('dnsServers')]"
              }
          },
          "resources":
          [
              {
                  "type": "Microsoft.Insights/diagnosticSettings",
                  "apiVersion": "2017-05-01-preview",
                  "name": "[variables('diagnosticsSettingsName')]",
                  "dependsOn": [
                      "[parameters('virtualNetworkName')]"
                  ],
                  "location": "global",
                  "properties": 
                   {
                      "storageAccountId": "..valid_id_here",
                      "logs": 
                      [
                          {
                              "category": "Administrative",
                              "enabled": true
                          },
                          {
                              "category": "Security",
                              "enabled": true
                          },
                          {
                              "category": "ServiceHealth",
                              "enabled": true
                          },
                          {
                              "category": "ResourceHealth",
                              "enabled": true
                          }
                      ]
                  }
              }
          ]
      }
  ],
  "outputs": {
      ..
  }
  </code></pre>