Bylaw

Gallery › SQL › Azure Community Policy

Audit SQL DB without Hybrid Licensing

Converted Policy Audit Disabled Mode All Version 1.0.0

Generate audit record if SQL DB is not configured for hybrid license

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONazurepolicy.json · 68 lines
{
  "name": "fd03a7ec-3418-4a73-a3a7-2aa4bd23cebe",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit SQL DB without Hybrid Licensing",
    "description": "Generate audit record if SQL DB is not configured for hybrid license",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.SQL/servers/databases"
          },
          {
            "field": "kind",
            "contains": "vcore"
          },
          {
            "field": "kind",
            "notContains": "pool"
          },
          {
            "field": "kind",
            "notContains": "serverless"
          },
          {
            "field": "kind",
            "notContains": "hyperscale"
          },
          {
            "field": "Microsoft.Sql/servers/databases/licenseType",
            "notEquals": "BasePrice"
          },
          {
            "field": "Microsoft.Sql/servers/databases/currentSku.name",
            "notContains": "GP_S"
          },
          {
            "field": "Microsoft.Sql/servers/databases/currentSku.name",
            "notEquals": "ElasticPool"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawfd03a7ec-3418-4a73-a3a7-2aa4bd23cebe.bylaw.ps1 · 36 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'fd03a7ec-3418-4a73-a3a7-2aa4bd23cebe' {

    Properties @{
        DisplayName = 'Audit SQL DB without Hybrid Licensing'
        Description = 'Generate audit record if SQL DB is not configured for hybrid license'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.SQL/servers/databases' {

        When {
            Field kind | Must -ContainText 'vcore'
            Field kind | Must -Not -ContainText 'pool'
            Field kind | Must -Not -ContainText 'serverless'
            Field kind | Must -Not -ContainText 'hyperscale'
            Field licenseType | Must -Not -Be 'BasePrice'
            Field currentSku.name | Must -Not -ContainText 'GP_S'
        }

        Require 'currentSku.name is ElasticPool' {
            Field currentSku.name | Must -Be 'ElasticPool'
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/SQL/audit-sql-db-without-hybrid-licensing/azurepolicy.json in Azure/Community-Policy, under the MIT licence.