Bylaw

Gallery › SQL › Azure Community Policy

Configure a private DNS Zone ID for Azure SQL Server sqlserver groupID

Uses Condition Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Configure private DNS zone group to override the DNS resolution for a Azure SQL Server sqlserver groupID private endpoint.

ConvertTo-Bylaw converted this policy, and proved it compiles back to the same definition. Conditions the language can't express yet are written as raw JSON with Condition.

Azure Policy JSONazurepolicy.json · 115 lines
{
  "name": "87b09efd-f716-4a73-a509-c8f831bba93e",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Configure a private DNS Zone ID for Azure SQL Server sqlserver groupID",
    "description": "Configure private DNS zone group to override the DNS resolution for a Azure SQL Server sqlserver groupID private endpoint.",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "Indexed",
    "parameters": {
      "privateDnsZoneId": {
        "type": "String",
        "metadata": {
          "displayName": "Configure a private DNS Zone ID for Azure SQL Server sqlserver groupID",
          "description": "Configure private DNS zone group to override the DNS resolution for a Azure SQL Server sqlserver groupID private endpoint.",
          "strongType": "Microsoft.Network/privateDnsZones",
          "assignPermissions": true
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/privateEndpoints"
          },
          {
            "count": {
              "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
              "where": {
                "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
                "equals": "sqlServer"
              }
            },
            "greaterOrEquals": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "privateDnsZoneId": {
                    "type": "string"
                  },
                  "privateEndpointName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "name": "[concat(parameters('privateEndpointName'), '/deployedByPolicy')]",
                    "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
                    "apiVersion": "2025-07-01",
                    "location": "[parameters('location')]",
                    "properties": {
                      "privateDnsZoneConfigs": [
                        {
                          "name": "privateDnsZone",
                          "properties": {
                            "privateDnsZoneId": "[parameters('privateDnsZoneId')]"
                          }
                        }
                      ]
                    }
                  }
                ]
              },
              "parameters": {
                "privateDnsZoneId": {
                  "value": "[parameters('privateDnsZoneId')]"
                },
                "privateEndpointName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                }
              }
            }
          }
        }
      }
    }
  }
}
Bylaw87b09efd-f716-4a73-a509-c8f831bba93e.bylaw.ps1 · 39 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '87b09efd-f716-4a73-a509-c8f831bba93e' {

    Properties @{
        DisplayName = 'Configure a private DNS Zone ID for Azure SQL Server sqlserver groupID'
        Description = 'Configure private DNS zone group to override the DNS resolution for a Azure SQL Server sqlserver groupID private endpoint.'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'Indexed'
    }

    Parameter PrivateDnsZoneId @{
        Type        = 'String'
        DisplayName = 'Configure a private DNS Zone ID for Azure SQL Server sqlserver groupID'
        Description = 'Configure private DNS zone group to override the DNS resolution for a Azure SQL Server sqlserver groupID private endpoint.'
        Metadata    = [ordered]@{ strongType = 'Microsoft.Network/privateDnsZones'; assignPermissions = $true }
    }
    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Network/privateEndpoints' {

        Require 'privateLinkServiceConnections.groupIds is as required' {
            Condition -Violation '{ "count": { "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]", "where": { "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]", "equals": "sqlServer" } }, "greaterOrEquals": 1 }'
        }
    }

    DeployIfNotExists 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups' -Role 'Network Contributor' -Effect (Param Effect) {
        Deployment -TemplateFile './templates/87b09efd-f716-4a73-a509-c8f831bba93e.json' -Parameters ([ordered]@{
                privateDnsZoneId    = (Param PrivateDnsZoneId)
                privateEndpointName = (Arm '[field(''name'')]')
                location            = (Arm '[field(''location'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: policyDefinitions/SQL/configure-a-private-dns-zone-id-for-sql-server-sqlserver-groupid/azurepolicy.json in Azure/Community-Policy, under the MIT licence.