Bylaw

Gallery › SQL › Azure Community Policy

Allowed SQL Database collations

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Will deny deploying databases with collations not listed as part of the allowed list

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

Azure Policy JSONazurepolicy.json · 58 lines
{
  "name": "be6d249b-259f-45ac-9a2d-74f4b42ad519",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Allowed SQL Database collations",
    "description": "Will deny deploying databases with collations not listed as part of the allowed list",
    "metadata": {
      "category": "SQL",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "listOfAllowedCollations": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Collation Names",
          "description": "A list of approved collations, example: Latin1_General_BIN;SQL_Latin1_General_CP1_CI_AS"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.SQL/servers/databases"
          },
          {
            "field": "name",
            "notEquals": "master"
          },
          {
            "not": {
              "field": "Microsoft.SQL/servers/databases/collation",
              "in": "[parameters('listOfAllowedCollations')]"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawbe6d249b-259f-45ac-9a2d-74f4b42ad519.bylaw.ps1 · 36 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'be6d249b-259f-45ac-9a2d-74f4b42ad519' {

    Properties @{
        DisplayName = 'Allowed SQL Database collations'
        Description = 'Will deny deploying databases with collations not listed as part of the allowed list'
        Category    = 'SQL'
        Version     = '1.0.0'
        Mode        = 'All'
    }

    Parameter ListOfAllowedCollations @{
        Type        = 'Array'
        DisplayName = 'Allowed Collation Names'
        Description = 'A list of approved collations, example: Latin1_General_BIN;SQL_Latin1_General_CP1_CI_AS'
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.SQL/servers/databases' {

        When {
            Field name | Must -Not -Be 'master'
        }

        Require 'collation is one of the ListOfAllowedCollations parameter' {
            Field collation | Must -BeIn (Param ListOfAllowedCollations)
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/SQL/allowed-sql-database-collations/azurepolicy.json in Azure/Community-Policy, under the MIT licence.