Bylaw

Gallery › SQL › Azure built-in policies

Private endpoint connections on Azure SQL Database should be enabled

Converted Policy Audit Disabled Mode Indexed Version 1.1.0

Private endpoint connections enforce secure communication by enabling private connectivity to Azure SQL Database.

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

Azure Policy JSONSqlServer_PrivateEndpoint_Audit.json · 55 lines
{
  "properties": {
    "displayName": "Private endpoint connections on Azure SQL Database should be enabled",
    "description": "Private endpoint connections enforce secure communication by enabling private connectivity to Azure SQL Database.",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "metadata": {
      "version": "1.1.0",
      "category": "SQL"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Sql/servers"
          },
          {
            "count": {
              "field": "Microsoft.Sql/servers/privateEndpointConnections[*]",
              "where": {
                "field": "Microsoft.Sql/servers/privateEndpointConnections[*].privateLinkServiceConnectionState.status",
                "equals": "Approved"
              }
            },
            "less": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/7698e800-9299-47a6-b3b6-5a0fee576eed",
  "name": "7698e800-9299-47a6-b3b6-5a0fee576eed"
}
Bylaw7698e800-9299-47a6-b3b6-5a0fee576eed.bylaw.ps1 · 30 lines
# Converted from SqlServer_PrivateEndpoint_Audit.json by ConvertTo-Bylaw.
Policy '7698e800-9299-47a6-b3b6-5a0fee576eed' {

    Properties @{
        DisplayName   = 'Private endpoint connections on Azure SQL Database should be enabled'
        Description   = 'Private endpoint connections enforce secure communication by enabling private connectivity to Azure SQL Database.'
        Version       = '1.1.0'
        Category      = 'SQL'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Sql/servers' {

        Require 'privateEndpointConnections and privateLinkServiceConnectionState.status are as required' {
            Count 'privateEndpointConnections[*]' -Where {
                Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
            } | Must -BeGreaterOrEqual 1
        }
    }

    Effect (Param Effect)
}

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