Bylaw

Gallery › SQL › Azure Community Policy

Allowed SQL DB SKUs

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy enables you to specify a set of SQL DB SKUs

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

Azure Policy JSONazurepolicy.json · 73 lines
{
  "name": "1cee483a-7053-4e29-99eb-5da1f7f73810",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Allowed SQL DB SKUs",
    "description": "This policy enables you to specify a set of SQL DB SKUs",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "All",
    "parameters": {
      "listOfSKUId": {
        "type": "Array",
        "metadata": {
          "description": "The list of SKUs that can be specified for SQL Databases.",
          "displayName": "Allowed SKU IDs"
        }
      },
      "listOfSKUName": {
        "type": "Array",
        "metadata": {
          "description": "The list of SKUs that can be specified for SQL Databases.",
          "displayName": "Allowed SKU Names"
        }
      },
      "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": {
              "anyOf": [
                {
                  "field": "Microsoft.SQL/servers/databases/requestedServiceObjectiveId",
                  "in": "[parameters('listOfSKUId')]"
                },
                {
                  "field": "Microsoft.SQL/servers/databases/requestedServiceObjectiveName",
                  "in": "[parameters('listOfSKUName')]"
                }
              ]
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw1cee483a-7053-4e29-99eb-5da1f7f73810.bylaw.ps1 · 44 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '1cee483a-7053-4e29-99eb-5da1f7f73810' {

    Properties @{
        DisplayName = 'Allowed SQL DB SKUs'
        Description = 'This policy enables you to specify a set of SQL DB SKUs'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'All'
    }

    Parameter ListOfSKUId @{
        Type        = 'Array'
        DisplayName = 'Allowed SKU IDs'
        Description = 'The list of SKUs that can be specified for SQL Databases.'
    }
    Parameter ListOfSKUName @{
        Type        = 'Array'
        DisplayName = 'Allowed SKU Names'
        Description = 'The list of SKUs that can be specified for SQL Databases.'
    }
    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 'requestedServiceObjectiveId and requestedServiceObjectiveName are as required' {
            AnyOf {
                Field requestedServiceObjectiveId | Must -BeIn (Param ListOfSKUId)
                Field requestedServiceObjectiveName | Must -BeIn (Param ListOfSKUName)
            }
        }
    }

    Effect (Param Effect)
}

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