Bylaw

Gallery › SQL › Azure Community Policy

PostgreSQL flexible servers - Allow certain version(s)

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

PostgreSQL flexible servers supports multiple Postgres version(s), This policy will only allow set version(s).

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

Azure Policy JSONazurepolicy.json · 56 lines
{
  "name": "d78f353a-a5e7-4747-8d31-62f361bafac5",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "mode": "Indexed",
    "displayName": "PostgreSQL flexible servers - Allow certain version(s)",
    "description": "PostgreSQL flexible servers supports multiple Postgres version(s), This policy will only allow set version(s).",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Deny",
        "allowedValues": [
          "Audit",
          "Disabled",
          "Deny"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      },
      "allowedVersions": {
        "type": "array",
        "defaultValue": [
          "16",
          "17"
        ],
        "metadata": {
          "displayName": "Postgres Version",
          "description": "Array of Postgres Server Versions allowed"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DBforPostgreSQL/flexibleServers"
          },
          {
            "value": "[contains(parameters('allowedVersions'),field('Microsoft.DBForPostgreSql/flexibleServers/version'))]",
            "equals": "false"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawd78f353a-a5e7-4747-8d31-62f361bafac5.bylaw.ps1 · 33 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'd78f353a-a5e7-4747-8d31-62f361bafac5' {

    Properties @{
        DisplayName = 'PostgreSQL flexible servers - Allow certain version(s)'
        Description = 'PostgreSQL flexible servers supports multiple Postgres version(s), This policy will only allow set version(s).'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled', 'Deny')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter AllowedVersions @{
        Type        = 'array'
        Default     = @('16', '17')
        DisplayName = 'Postgres Version'
        Description = 'Array of Postgres Server Versions allowed'
    }

    Resource 'Microsoft.DBforPostgreSQL/flexibleServers' {

        Require 'version is as required' {
            Arm '[contains(parameters(''allowedVersions''),field(''Microsoft.DBForPostgreSql/flexibleServers/version''))]' | Must -Not -Be 'false'
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/SQL/deny-postgresql-version/azurepolicy.json in Azure/Community-Policy, under the MIT licence.