Gallery › Network › Azure Community Policy
deploy-private-endpoint-private-dns-zone-link
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode All Version 1.0.0
need to add description
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 227 lines
{
"name": "e9e5a351-858d-4738-b0e6-dbbdc3cb425d",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "deploy-private-endpoint-private-dns-zone-link",
"description": "need to add description",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"mode": "All",
"parameters": {
"dnsZoneProductionSubscriptionId": {
"type": "String",
"metadata": {
"displayName": "Production DNS Zones Subscription ID",
"description": "The ID of the subscription where the production DNS Zones reside"
}
},
"dnsZoneProductionResourceGroupName": {
"type": "String",
"metadata": {
"displayName": "Production DNS Zones Resource Group Name",
"description": "Name of the resource group where all of the production DNS Zones reside"
}
},
"dnsZoneNonProductionSubscriptionId": {
"type": "String",
"metadata": {
"displayName": "Non-Production DNS Zones Subscription ID",
"description": "The ID of the subscription where the non-production DNS Zones reside"
}
},
"dnsZoneNonProductionResourceGroupName": {
"type": "String",
"metadata": {
"displayName": "Non-Production DNS Zones Resource Group Name",
"description": "Name of the resource group where all of the non-production DNS Zones reside"
}
},
"environmentTagName": {
"type": "String",
"metadata": {
"displayName": "Environment Tag Name",
"description": "This is the name of the tag that will be used to identify the environment type"
}
},
"environmentProductionTagValue": {
"type": "String",
"metadata": {
"displayName": "Production Tag Value",
"description": "The tag value that will be assigned to production resources"
}
},
"environmentNonProductionTagValue": {
"type": "String",
"metadata": {
"displayName": "Non-Production Tag Value",
"description": "The tag value that will be assigned to non-production resources"
}
},
"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"
},
{
"anyOf": [
{
"field": "[concat('tags[', parameters('environmentTagName'), ']')]",
"equals": "[parameters('environmentProductionTagValue')]"
},
{
"field": "[concat('tags[', parameters('environmentTagName'), ']')]",
"equals": "[parameters('environmentNonProductionTagValue')]"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"
],
"existenceCondition": {
"anyOf": [
{
"value": "[string(field('Microsoft.Network/privateEndpoints/privateDnsZoneGroups/privateDnsZoneConfigs[*].privateDnsZoneId'))]",
"contains": "[concat('/subscriptions/', parameters('dnsZoneProductionSubscriptionId'), '/resourceGroups/', parameters('dnsZoneProductionResourceGroupName'), '/providers/Microsoft.Network/privateDnsZones/')]"
},
{
"value": "[string(field('Microsoft.Network/privateEndpoints/privateDnsZoneGroups/privateDnsZoneConfigs[*].privateDnsZoneId'))]",
"contains": "[concat('/subscriptions/', parameters('dnsZoneNonProductionSubscriptionId'), '/resourceGroups/', parameters('dnsZoneNonProductionResourceGroupName'), '/providers/Microsoft.Network/privateDnsZones/')]"
}
]
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateEndpointName": {
"type": "String"
},
"groupId": {
"type": "Array"
},
"location": {
"type": "String"
},
"dnsZoneProductionSubscriptionId": {
"type": "String"
},
"dnsZoneProductionResourceGroupName": {
"type": "String"
},
"dnsZoneNonProductionSubscriptionId": {
"type": "String"
},
"dnsZoneNonProductionResourceGroupName": {
"type": "String"
},
"environmentTagValue": {
"type": "String"
},
"environmentProductionTagValue": {
"type": "String"
}
},
"variables": {
"pvtendpointdnsgroupname": "[concat(parameters('privateEndpointName'),'/default')]",
"groupIdMap": {
"sqlServer": "privatelink.database.windows.net",
"blob": "privatelink.blob.core.windows.net",
"blob_secondary": "privatelink.blob.core.windows.net",
"table": "table.core.windows.net",
"table_secondary": "table.core.windows.net",
"queue": "privatelink.queue.core.windows.net",
"queue_secondary": "privatelink.queue.core.windows.net",
"file": "privatelink.file.core.windows.net",
"file_secondary": "privatelink.file.core.windows.net",
"web": "privatelink.web.core.windows.net",
"web_secondary": "privatelink.web.core.windows.net"
},
"productionZoneID": "[concat('/subscriptions/', parameters('dnsZoneProductionSubscriptionId'), '/resourceGroups/', parameters('dnsZoneProductionResourceGroupName'), '/providers/Microsoft.Network/privateDnsZones/', variables('groupIdMap')[parameters('groupId')[0]])]",
"nonProductionZoneID": "[concat('/subscriptions/', parameters('dnsZoneNonProductionSubscriptionId'), '/resourceGroups/', parameters('dnsZoneNonProductionResourceGroupName'), '/providers/Microsoft.Network/privateDnsZones/', variables('groupIdMap')[parameters('groupId')[0]])]"
},
"resources": [
{
"type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
"apiVersion": "2020-05-01",
"name": "[variables('pvtendpointdnsgroupname')]",
"location": "[parameters('location')]",
"properties": {
"copy": [
{
"name": "privateDnsZoneConfigs",
"count": "[length(parameters('groupId'))]",
"input": {
"name": "[concat('config', copyindex('privateDnsZoneConfigs',1))]",
"properties": {
"privateDnsZoneId": "[if(equals(parameters('environmentTagValue'), parameters('environmentProductionTagValue')), concat('/subscriptions/', parameters('dnsZoneProductionSubscriptionId'), '/resourceGroups/', parameters('dnsZoneProductionResourceGroupName'), '/providers/Microsoft.Network/privateDnsZones/', variables('groupIdMap')[parameters('groupId')[copyIndex('privateDnsZoneConfigs')]]), concat('/subscriptions/', parameters('dnsZoneNonProductionSubscriptionId'), '/resourceGroups/', parameters('dnsZoneNonProductionResourceGroupName'), '/providers/Microsoft.Network/privateDnsZones/', variables('groupIdMap')[parameters('groupId')[copyIndex('privateDnsZoneConfigs')]]))]"
}
}
}
]
}
}
]
},
"parameters": {
"privateEndpointName": {
"value": "[field('name')]"
},
"groupId": {
"value": "[field('Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]')]"
},
"location": {
"value": "[field('location')]"
},
"environmentTagValue": {
"value": "[field(concat('tags[', parameters('environmentTagName'), ']'))]"
},
"environmentProductionTagValue": {
"value": "[parameters('environmentProductionTagValue')]"
},
"dnsZoneProductionSubscriptionId": {
"value": "[parameters('dnsZoneProductionSubscriptionId')]"
},
"dnsZoneProductionResourceGroupName": {
"value": "[parameters('dnsZoneProductionResourceGroupName')]"
},
"dnsZoneNonProductionSubscriptionId": {
"value": "[parameters('dnsZoneProductionSubscriptionId')]"
},
"dnsZoneNonProductionResourceGroupName": {
"value": "[parameters('dnsZoneProductionResourceGroupName')]"
}
}
}
}
}
}
}
}
}Bylawe9e5a351-858d-4738-b0e6-dbbdc3cb425d.bylaw.ps1 · 84 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'e9e5a351-858d-4738-b0e6-dbbdc3cb425d' {
Properties @{
DisplayName = 'deploy-private-endpoint-private-dns-zone-link'
Description = 'need to add description'
Version = '1.0.0'
Category = 'Network'
Mode = 'All'
}
Parameter DnsZoneProductionSubscriptionId @{
Type = 'String'
DisplayName = 'Production DNS Zones Subscription ID'
Description = 'The ID of the subscription where the production DNS Zones reside'
}
Parameter DnsZoneProductionResourceGroupName @{
Type = 'String'
DisplayName = 'Production DNS Zones Resource Group Name'
Description = 'Name of the resource group where all of the production DNS Zones reside'
}
Parameter DnsZoneNonProductionSubscriptionId @{
Type = 'String'
DisplayName = 'Non-Production DNS Zones Subscription ID'
Description = 'The ID of the subscription where the non-production DNS Zones reside'
}
Parameter DnsZoneNonProductionResourceGroupName @{
Type = 'String'
DisplayName = 'Non-Production DNS Zones Resource Group Name'
Description = 'Name of the resource group where all of the non-production DNS Zones reside'
}
Parameter EnvironmentTagName @{
Type = 'String'
DisplayName = 'Environment Tag Name'
Description = 'This is the name of the tag that will be used to identify the environment type'
}
Parameter EnvironmentProductionTagValue @{
Type = 'String'
DisplayName = 'Production Tag Value'
Description = 'The tag value that will be assigned to production resources'
}
Parameter EnvironmentNonProductionTagValue @{
Type = 'String'
DisplayName = 'Non-Production Tag Value'
Description = 'The tag value that will be assigned to non-production resources'
}
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 'tag (Param EnvironmentTagName) is not the EnvironmentProductionTagValue parameter' {
Tag (Param EnvironmentTagName) | Must -Not -Be (Param EnvironmentProductionTagValue) -IfPresent
}
Require 'tag (Param EnvironmentTagName) is not the EnvironmentNonProductionTagValue parameter' {
Tag (Param EnvironmentTagName) | Must -Not -Be (Param EnvironmentNonProductionTagValue) -IfPresent
}
}
DeployIfNotExists 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups' -Role 'Owner' -Effect (Param Effect) {
Require 'privateDnsZoneConfigs.privateDnsZoneId is as required' {
AnyOf {
Arm '[string(field(''Microsoft.Network/privateEndpoints/privateDnsZoneGroups/privateDnsZoneConfigs[*].privateDnsZoneId''))]' | Must -ContainText (Arm '[concat(''/subscriptions/'', parameters(''dnsZoneProductionSubscriptionId''), ''/resourceGroups/'', parameters(''dnsZoneProductionResourceGroupName''), ''/providers/Microsoft.Network/privateDnsZones/'')]')
Arm '[string(field(''Microsoft.Network/privateEndpoints/privateDnsZoneGroups/privateDnsZoneConfigs[*].privateDnsZoneId''))]' | Must -ContainText (Arm '[concat(''/subscriptions/'', parameters(''dnsZoneNonProductionSubscriptionId''), ''/resourceGroups/'', parameters(''dnsZoneNonProductionResourceGroupName''), ''/providers/Microsoft.Network/privateDnsZones/'')]')
}
}
Deployment -TemplateFile './templates/e9e5a351-858d-4738-b0e6-dbbdc3cb425d.json' -Parameters ([ordered]@{
privateEndpointName = (Arm '[field(''name'')]')
groupId = (Arm '[field(''Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]'')]')
location = (Arm '[field(''location'')]')
environmentTagValue = (Arm '[field(concat(''tags['', parameters(''environmentTagName''), '']''))]')
environmentProductionTagValue = (Param EnvironmentProductionTagValue)
dnsZoneProductionSubscriptionId = (Param DnsZoneProductionSubscriptionId)
dnsZoneProductionResourceGroupName = (Param DnsZoneProductionResourceGroupName)
dnsZoneNonProductionSubscriptionId = (Param DnsZoneProductionSubscriptionId)
dnsZoneNonProductionResourceGroupName = (Param DnsZoneProductionResourceGroupName)
})
}
}Its deployment templates are written beside it:
templates/e9e5a351-858d-4738-b0e6-dbbdc3cb425d.json
Source: policyDefinitions/Network/deploy-private-endpoint-private-dns-zone-link/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw