Bylaw

Gallery › SQL › Azure Community Policy

Allowed SQL Elastic Pool capacity

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Will deny deploying elastic pools with capacity (vcores) beyond the allowed list

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

Azure Policy JSONazurepolicy.json · 52 lines
{
  "name": "0da5edcf-ea7f-4a00-b592-eecbd150eb93",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Allowed SQL Elastic Pool capacity",
    "description": "Will deny deploying elastic pools with capacity (vcores) beyond the allowed list",
    "metadata": {
      "category": "SQL",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "MaxPoolCapacityVCores": {
        "type": "Integer",
        "metadata": {
          "displayName": "Maximum vCores allowed for the pool",
          "description": "Top defined approved vCores"
        }
      },
      "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/elasticPools"
          },
          {
            "field": "Microsoft.Sql/servers/elasticpools/sku.capacity",
            "greater": "[parameters('MaxPoolCapacityVCores')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw0da5edcf-ea7f-4a00-b592-eecbd150eb93.bylaw.ps1 · 33 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '0da5edcf-ea7f-4a00-b592-eecbd150eb93' {

    Properties @{
        DisplayName = 'Allowed SQL Elastic Pool capacity'
        Description = 'Will deny deploying elastic pools with capacity (vcores) beyond the allowed list'
        Category    = 'SQL'
        Version     = '1.0.0'
        Mode        = 'All'
    }

    Parameter MaxPoolCapacityVCores @{
        Type        = 'Integer'
        DisplayName = 'Maximum vCores allowed for the pool'
        Description = 'Top defined approved vCores'
        JsonName    = 'MaxPoolCapacityVCores'
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Sql/servers/elasticPools' {

        Require 'sku.capacity is at most the MaxPoolCapacityVCores parameter' {
            Field sku.capacity | Must -BeLessOrEqual (Param MaxPoolCapacityVCores) -IfPresent
        }
    }

    Effect (Param Effect)
}

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