Gallery › Network › Azure Community Policy
Configure Private Endpoint for PaaS services to use private DNS zones
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0
This policy will deploy Private DNS Zone Configs for any kind of Private Endpoint - With compliance working as it should and resolving the openAi - Foundry 3v1 dns problem
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 283 lines
{
"name": "6f69622e-dbb3-4a41-92bf-071bc1be1752",
"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 - With compliance working as it should and resolving the openAi - Foundry 3v1 dns problem",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"mode": "Indexed",
"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",
"evaluationDelay": "PT1M",
"name": "[field('name')]",
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/customDnsConfigs[*]",
"exists": true
},
{
"count": {
"field": "Microsoft.Network/privateEndpoints/customDnsConfigs[*]"
},
"equals": 0
}
]
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7"
],
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"privateEndpointName": {
"value": "[field('name')]"
},
"privateEndpointId": {
"value": "[field('id')]"
},
"location": {
"value": "[field('location')]"
},
"dnsZoneGroupName": {
"value": "[parameters('dnsZoneGroupName')]"
},
"dnsConfigsRG": {
"value": "[parameters('dnsConfigsRG')]"
},
"privateEndpointPrivateLinkServiceId": {
"value": "[parameters('privateEndpointPrivateLinkServiceId')]"
},
"privateEndpointGroupId": {
"value": "[parameters('privateEndpointGroupId')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateEndpointName": {
"type": "string"
},
"privateEndpointId": {
"type": "string"
},
"location": {
"type": "string"
},
"dnsZoneGroupName": {
"type": "string"
},
"dnsConfigsRG": {
"type": "string"
},
"privateEndpointPrivateLinkServiceId": {
"type": "string"
},
"privateEndpointGroupId": {
"type": "string"
}
},
"variables": {
"getPECurrentProperties": "[concat('getPECurrentProperties-', uniqueString(deployment().name))]",
"deployPEDNSConfigs": "[concat('deployPEDNSConfigs-', uniqueString(deployment().name))]",
"mappedName": "[concat(tolower(parameters('privateEndpointPrivateLinkServiceId')), '/', tolower(parameters('privateEndpointGroupId')) )]",
"mappings":{
"microsoft.keyvault/vaults/vault" : [
".vault.",
".vaultcore."
]
}
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-06-01",
"name": "[variables('getPECurrentProperties')]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"privateEndpointId": {
"value": "[parameters('privateEndpointId')]"
}
},
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateEndpointId": {
"type": "string"
}
},
"outputs": {
"resource": {
"type": "object",
"value": "[reference(parameters('privateEndpointId'), '2024-10-01', 'Full')]"
}
},
"resources": []
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-06-01",
"dependsOn": [
"[variables('getPECurrentProperties')]"
],
"name": "[variables('deployPEDNSConfigs')]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"privateEndpointName": {
"value": "[parameters('privateEndpointName')]"
},
"location": {
"value": "[parameters('location')]"
},
"customDnsConfigs": {
"value": "[if(equals(tryGet(variables('mappings'), variables('mappedName')), null()), map(coalesce(reference(variables('getPECurrentProperties')).outputs.resource.value.properties.customDnsConfigs, createArray()), lambda('dns', lambdaVariables('dns').fqdn)), map(coalesce(reference(variables('getPECurrentProperties')).outputs.resource.value.properties.customDnsConfigs, createArray()), lambda('dns', replace(lambdaVariables('dns').fqdn, tryGet(variables('mappings'), variables('mappedName'))[0], tryGet(variables('mappings'), variables('mappedName'))[1]))) )]"
},
"dnsZoneGroupName": {
"value": "[parameters('dnsZoneGroupName')]"
},
"dnsConfigsRG": {
"value": "[parameters('dnsConfigsRG')]"
}
},
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateEndpointName": {
"type": "string"
},
"location": {
"type": "string"
},
"customDnsConfigs": {
"type": "array"
},
"dnsZoneGroupName": {
"type": "string"
},
"dnsConfigsRG": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('privateEndpointName'), '/', parameters('dnsZoneGroupName'))]",
"type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
"apiVersion": "2024-10-01",
"location": "[parameters('location')]",
"properties": {
"copy": [
{
"name": "privateDnsZoneConfigs",
"count": "[length(parameters('customDnsConfigs'))]",
"input": {
"name": "[concat('privatelink', replace(substring(parameters('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')], indexOf(parameters('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')], '.'), sub(length(parameters('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')]), indexOf(parameters('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')], '.'))), '.', '-'))]",
"properties": {
"privateDnsZoneId": "[concat(parameters('dnsConfigsRG'), '/providers/Microsoft.Network/privateDnsZones/privatelink', substring(parameters('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')], indexOf(parameters('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')], '.'), sub(length(parameters('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')]), indexOf(parameters('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')], '.'))) ) ]"
}
}
}
]
}
}
]
}
}
}
]
}
}
}
}
}
},
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
},
"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"
}
},
"dnsZoneGroupName": {
"type": "String",
"metadata": {
"displayName": "DNS Zone Group Name",
"description": "Private DNS Zone Group Name"
},
"defaultValue": "deployedByPolicy"
},
"dnsConfigsRG": {
"type": "String",
"metadata": {
"displayName": "Private DNS Zone Resource Group Resource ID",
"description": "Private DNS Zone Resource Group where the private dns zones exist."
}
}
}
}
}Bylaw6f69622e-dbb3-4a41-92bf-071bc1be1752.bylaw.ps1 · 70 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '6f69622e-dbb3-4a41-92bf-071bc1be1752' {
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 - With compliance working as it should and resolving the openAi - Foundry 3v1 dns problem'
Version = '1.0.0'
Category = 'Network'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter PrivateEndpointPrivateLinkServiceId @{
Type = 'string'
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'
}
Parameter PrivateEndpointGroupId @{
Type = 'string'
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'
}
Parameter DnsZoneGroupName @{
Default = 'deployedByPolicy'
DisplayName = 'DNS Zone Group Name'
Description = 'Private DNS Zone Group Name'
}
Parameter DnsConfigsRG @{
Type = 'String'
DisplayName = 'Private DNS Zone Resource Group Resource ID'
Description = 'Private DNS Zone Resource Group where the private dns zones exist.'
}
Resource 'Microsoft.Network/privateEndpoints' {
Require 'privateLinkServiceConnections, privateLinkServiceId and groupIds are as required' {
Count 'privateLinkServiceConnections[*]' -Where {
Field privateLinkServiceId | Must -ContainText (Param PrivateEndpointPrivateLinkServiceId)
Field groupIds | Must -Exist
Count 'groupIds[*]' -Where {
Element | Must -Not -Be (Param PrivateEndpointGroupId)
} | Must -Be 0
} | Must -Be 0
}
}
DeployIfNotExists 'Microsoft.Network/privateEndpoints' -Role 'Network Contributor' -Name (Arm '[field(''name'')]') -EvaluationDelay PT1M -Effect (Param Effect) {
Require 'customDnsConfigs is as required' {
Field customDnsConfigs | Must -Exist
Each 'customDnsConfigs[*]' {
Element | Must -Exist
}
Count 'customDnsConfigs[*]' | Must -Be 0
}
Deployment -TemplateFile './templates/6f69622e-dbb3-4a41-92bf-071bc1be1752.json' -Parameters ([ordered]@{
privateEndpointName = (Arm '[field(''name'')]')
privateEndpointId = (Arm '[field(''id'')]')
location = (Arm '[field(''location'')]')
dnsZoneGroupName = (Param DnsZoneGroupName)
dnsConfigsRG = (Param DnsConfigsRG)
privateEndpointPrivateLinkServiceId = (Param PrivateEndpointPrivateLinkServiceId)
privateEndpointGroupId = (Param PrivateEndpointGroupId)
})
}
}Its deployment templates are written beside it:
templates/6f69622e-dbb3-4a41-92bf-071bc1be1752.json
Source: policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw