Gallery › SQL › Azure Community Policy
Configure a private DNS Zone ID for Azure Database for MySQL flexible server mysqlServer 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 Database for MySQL flexible server mysqlServer 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": "0074cf0a-1026-46e4-be24-d3b4909cf61e",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Configure a private DNS Zone ID for Azure Database for MySQL flexible server mysqlServer groupID",
"description": "Configure private DNS zone group to override the DNS resolution for a Azure Database for MySQL flexible server mysqlServer 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 Database for MySQL flexible server mysqlServer groupID",
"description": "Configure private DNS zone group to override the DNS resolution for a Azure Database for MySQL flexible server mysqlServer 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": "mysqlServer"
}
},
"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')]"
}
}
}
}
}
}
}
}
}Bylaw0074cf0a-1026-46e4-be24-d3b4909cf61e.bylaw.ps1 · 39 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '0074cf0a-1026-46e4-be24-d3b4909cf61e' {
Properties @{
DisplayName = 'Configure a private DNS Zone ID for Azure Database for MySQL flexible server mysqlServer groupID'
Description = 'Configure private DNS zone group to override the DNS resolution for a Azure Database for MySQL flexible server mysqlServer groupID private endpoint.'
Version = '1.0.0'
Category = 'SQL'
Mode = 'Indexed'
}
Parameter PrivateDnsZoneId @{
Type = 'String'
DisplayName = 'Configure a private DNS Zone ID for Azure Database for MySQL flexible server mysqlServer groupID'
Description = 'Configure private DNS zone group to override the DNS resolution for a Azure Database for MySQL flexible server mysqlServer 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": "mysqlServer" } }, "greaterOrEquals": 1 }'
}
}
DeployIfNotExists 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups' -Role 'Network Contributor' -Effect (Param Effect) {
Deployment -TemplateFile './templates/0074cf0a-1026-46e4-be24-d3b4909cf61e.json' -Parameters ([ordered]@{
privateDnsZoneId = (Param PrivateDnsZoneId)
privateEndpointName = (Arm '[field(''name'')]')
location = (Arm '[field(''location'')]')
})
}
}Its deployment templates are written beside it:
templates/0074cf0a-1026-46e4-be24-d3b4909cf61e.json
Source: policyDefinitions/Database for MySQL/configure-a-private-dns-zone-id-for-mysql-flexible-server-mysqlserver-groupid/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw