{
  "properties": {
    "displayName": "Deploy Threat Detection on SQL servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy ensures that Threat Detection is enabled on SQL Servers.",
    "metadata": {
      "version": "2.0.0",
      "category": "SQL"
    },
    "parameters": {},
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Sql/servers"
          },
          {
            "field": "kind",
            "notContains": "analytics"
          }
        ]
      },
      "then": {
        "effect": "DeployIfNotExists",
        "details": {
          "type": "Microsoft.Sql/servers/securityAlertPolicies",
          "name": "Default",
          "existenceCondition": {
            "field": "Microsoft.Sql/securityAlertPolicies.state",
            "equals": "Enabled"
          },
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/056cd41c-7e88-42e1-933e-88ba6a50c9c3"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "serverName": {
                    "type": "string"
                  }
                },
                "variables": {},
                "resources": [
                  {
                    "name": "[concat(parameters('serverName'), '/Default')]",
                    "type": "Microsoft.Sql/servers/securityAlertPolicies",
                    "apiVersion": "2017-03-01-preview",
                    "properties": {
                      "state": "Enabled",
                      "emailAccountAdmins": false
                    }
                  }
                ]
              },
              "parameters": {
                "serverName": {
                  "value": "[field('name')]"
                }
              }
            }
          }
        }
      }
    }
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/36d49e87-48c4-4f2e-beed-ba4ed02b71f5",
  "name": "36d49e87-48c4-4f2e-beed-ba4ed02b71f5"
}