Bylaw

Gallery › PostgreSQL › Azure built-in policies

Log checkpoints should be enabled for PostgreSQL flexible servers

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0

This policy helps audit any PostgreSQL flexible servers in your environment without log_checkpoints setting enabled.

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

Azure Policy JSONFlexibleServers_EnableLogCheckpoint_AINE.json · 49 lines
{
  "properties": {
    "displayName": "Log checkpoints should be enabled for PostgreSQL flexible servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy helps audit any PostgreSQL flexible servers in your environment without log_checkpoints setting enabled.",
    "metadata": {
      "version": "1.0.0",
      "category": "PostgreSQL"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.DBforPostgreSQL/flexibleServers"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.DBforPostgreSQL/flexibleServers/configurations",
          "name": "log_checkpoints",
          "existenceCondition": {
            "field": "Microsoft.DBforPostgreSQL/flexibleServers/configurations/value",
            "equals": "ON"
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/70be9e12-c935-49ac-9bd8-fd64b85c1f87",
  "name": "70be9e12-c935-49ac-9bd8-fd64b85c1f87"
}
Bylaw70be9e12-c935-49ac-9bd8-fd64b85c1f87.bylaw.ps1 · 28 lines
# Converted from FlexibleServers_EnableLogCheckpoint_AINE.json by ConvertTo-Bylaw.
Policy '70be9e12-c935-49ac-9bd8-fd64b85c1f87' {

    Properties @{
        DisplayName   = 'Log checkpoints should be enabled for PostgreSQL flexible servers'
        Description   = 'This policy helps audit any PostgreSQL flexible servers in your environment without log_checkpoints setting enabled.'
        Version       = '1.0.0'
        Category      = 'PostgreSQL'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.DBforPostgreSQL/flexibleServers'

    AuditIfNotExists 'Microsoft.DBforPostgreSQL/flexibleServers/configurations' -Name 'log_checkpoints' -Effect (Param Effect) {
        Require 'value is ON' {
            Field value | Must -Be 'ON'
        }
    }
}

Source: built-in-policies/policyDefinitions/PostgreSQL/FlexibleServers_EnableLogCheckpoint_AINE.json in Azure/azure-policy, under the MIT licence.