Gallery › Network › Azure Community Policy
Create Private DNS Zone Virtual Network Link to Virtual Networks if not available
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode All Version 1.0.0
Create Private DNS Zone Virtual Network Link to Virtual Networks if not available
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 124 lines
{
"name": "1ef5dbf9-dbc7-43fc-8847-e887f76e67a0",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Create Private DNS Zone Virtual Network Link to Virtual Networks if not available",
"description": "Create Private DNS Zone Virtual Network Link to Virtual Networks if not available",
"metadata": {
"category": "Network",
"version": "1.0.0"
},
"mode": "All",
"parameters": {
"virtualNetworkResourceId": {
"defaultValue": [],
"metadata": {
"description": "Resource Ids of a vNet to link. The format must be: '/subscriptions/{subscription id}/resourceGroups/{resourceGroup name}/providers/Microsoft.Network/virtualNetworks/{virtual network name}",
"displayName": "Vnet Resource IDs"
},
"type": "array"
},
"registrationEnabled": {
"defaultValue": false,
"metadata": {
"description": "Enables automatic DNS registration in the zone for the linked vNet.",
"displayName": "Enable Registration"
},
"type": "Boolean"
},
"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": [
{
"equals": "Microsoft.Network/privateDnsZones",
"field": "type"
}
]
},
"then": {
"details": {
"existenceCondition": {
"allOf": [
{
"equals": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
"field": "type"
},
{
"in": "[parameters('virtualNetworkResourceId')]",
"field": "Microsoft.Network/privateDnsZones/virtualNetworkLinks/virtualNetwork.id"
}
]
},
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"privateDnsZoneName": {
"value": "[field('name')]"
},
"virtualNetworkResourceId": {
"value": "[parameters('virtualNetworkResourceId')]"
},
"registrationEnabled": {
"value": "[parameters('registrationEnabled')]"
}
},
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateDnsZoneName": {
"type": "String"
},
"virtualNetworkResourceId": {
"type": "array"
},
"registrationEnabled": {
"type": "bool"
}
},
"resources": [
{
"type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
"apiVersion": "2018-09-01",
"name": "[concat(parameters('privateDnsZoneName'),'/',concat(parameters('privateDnsZoneName'),'-', last(split(parameters('virtualNetworkResourceId')[copyIndex()],'/'))))]",
"location": "global",
"copy": {
"name": "vnetlink-counter",
"count": "[length(parameters('virtualNetworkResourceId'))]"
},
"properties": {
"registrationEnabled": "[parameters('registrationEnabled')]",
"virtualNetwork": {
"id": "[parameters('virtualNetworkResourceId')[copyIndex()]]"
}
}
}
]
}
}
},
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b12aa53e-6015-4669-85d0-8515ebb3ae7f"
],
"type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks"
},
"effect": "[parameters('effect')]"
}
}
}
}Bylaw1ef5dbf9-dbc7-43fc-8847-e887f76e67a0.bylaw.ps1 · 44 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '1ef5dbf9-dbc7-43fc-8847-e887f76e67a0' {
Properties @{
DisplayName = 'Create Private DNS Zone Virtual Network Link to Virtual Networks if not available'
Description = 'Create Private DNS Zone Virtual Network Link to Virtual Networks if not available'
Category = 'Network'
Version = '1.0.0'
Mode = 'All'
}
Parameter VirtualNetworkResourceId @{
Type = 'array'
Default = @()
DisplayName = 'Vnet Resource IDs'
Description = 'Resource Ids of a vNet to link. The format must be: ''/subscriptions/{subscription id}/resourceGroups/{resourceGroup name}/providers/Microsoft.Network/virtualNetworks/{virtual network name}'
}
Parameter RegistrationEnabled @{
Type = 'Boolean'
Default = $false
DisplayName = 'Enable Registration'
Description = 'Enables automatic DNS registration in the zone for the linked vNet.'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Network/privateDnsZones'
DeployIfNotExists 'Microsoft.Network/privateDnsZones/virtualNetworkLinks' -Role 'Private DNS Zone Contributor' -Effect (Param Effect) {
Require 'type and virtualNetwork.id are as required' {
Field type | Must -Be 'Microsoft.Network/privateDnsZones/virtualNetworkLinks'
Field virtualNetwork.id | Must -BeIn (Param VirtualNetworkResourceId)
}
Deployment -TemplateFile './templates/1ef5dbf9-dbc7-43fc-8847-e887f76e67a0.json' -Parameters ([ordered]@{
privateDnsZoneName = (Arm '[field(''name'')]')
virtualNetworkResourceId = (Param VirtualNetworkResourceId)
registrationEnabled = (Param RegistrationEnabled)
})
}
}Its deployment templates are written beside it:
templates/1ef5dbf9-dbc7-43fc-8847-e887f76e67a0.json
Source: policyDefinitions/Network/create-private-dns-zone-virtual-network-link-to-virtual-networks-if-not-available/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw