Bylaw

Gallery › Network › Azure Community Policy

Configure Private Endpoint for PaaS services to use private DNS zones

Doesn't convert yet Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0

This policy will deploy Private DNS Zone Configs for any kind of Private Endpoint

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 141 lines
{
  "name": "c0d5f500-670f-458d-a558-64d673bf3833",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Configure Private Endpoint for PaaS services to use private DNS zones",
    "description": "This policy will deploy Private DNS Zone Configs for any kind of Private Endpoint",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "mode": "Indexed",
    "parameters": {
      "privateDnsZoneIds": {
        "type": "array",
        "metadata": {
          "displayName": "Array of Private Dns Zone Id",
          "description": "The list of private DNS zone to deploy in a new private DNS zone group and link to the private endpoint"
        }
      },
      "privateEndpointPrivateLinkServiceId": {
        "type": "string",
        "metadata": {
          "displayName": "Private Endpoint Link Service Id. The list is available in this link: https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-dns#azure-services-dns-zone-configuration",
          "description": "A group Id for the private endpoint"
        }
      },
      "privateEndpointGroupId": {
        "type": "string",
        "metadata": {
          "displayName": "Private Endpoint Group Id",
          "description": "A group Id for the private endpoint. The list is available in this link: https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-dns#azure-services-dns-zone-configuration"
        }
      },
      "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[*]",
              "where": {
                "allOf": [
                  {
                    "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
                    "contains": "[parameters('privateEndpointPrivateLinkServiceId')]"
                  },
                  {
                    "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
                    "equals": "[parameters('privateEndpointGroupId')]"
                  }
                ]
              }
            },
            "greaterOrEquals": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
          "evaluationDelay": "AfterProvisioningSuccess",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "name": "parameters('privateEndpointPrivateLinkServiceId')",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "privateDnsZoneIds": {
                    "type": "array"
                  },
                  "privateEndpointName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
                    "apiVersion": "2020-03-01",
                    "name": "[concat(parameters('privateEndpointName'), '/deployedByPolicy')]",
                    "location": "[parameters('location')]",
                    "properties": {
                      "copy": [
                        {
                          "name": "privateDnsZoneConfigs",
                          "count": "[length(parameters('privateDnsZoneIds'))]",
                          "input": {
                            "name": "[concat(last(split(parameters('privateDnsZoneIds')[copyIndex('privateDnsZoneConfigs')], '/')), '-', parameters('privateEndpointName'))]",
                            "properties": {
                              "privateDnsZoneId": "[parameters('privateDnsZoneIds')[copyIndex('privateDnsZoneConfigs')]]"
                            }
                          }
                        }
                      ]
                    }
                  }
                ]
              },
              "parameters": {
                "privateDnsZoneIds": {
                  "value": "[parameters('privateDnsZoneIds')]"
                },
                "privateEndpointName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                }
              }
            }
          }
        }
      }
    }
  }
}

Source: policyDefinitions/Network/configure-private-endpoint-for-paas-services-to-use-private-dns-zones/azurepolicy.json in Azure/Community-Policy, under the MIT licence.