diff --git a/policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.json b/policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.json index e204d0bf..ae54b462 100644 --- a/policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.json +++ b/policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.json @@ -1,283 +1,292 @@ { - "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 - } - ] + "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" }, - "then": { - "effect": "[parameters('effect')]", - "details": { - "type": "Microsoft.Network/privateEndpoints", - "evaluationDelay": "PT1M", - "name": "[field('name')]", - "existenceCondition": { - "allOf": [ - { - "field": "Microsoft.Network/privateEndpoints/customDnsConfigs[*]", - "exists": true + "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')]" + } + ] + } }, - { - "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')]" + "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 }, - "privateEndpointGroupId": { - "value": "[parameters('privateEndpointGroupId')]" + { + "count": { + "field": "Microsoft.Network/privateEndpoints/customDnsConfigs[*]" + }, + "equals": 0 } - }, - "template": { - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", + ] + }, + "roleDefinitionIds": [ + "/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7" + ], + "deployment": { + "properties": { + "mode": "incremental", "parameters": { "privateEndpointName": { - "type": "string" + "value": "[field('name')]" }, "privateEndpointId": { - "type": "string" + "value": "[field('id')]" }, "location": { - "type": "string" + "value": "[field('location')]" }, "dnsZoneGroupName": { - "type": "string" + "value": "[parameters('dnsZoneGroupName')]" }, "dnsConfigsRG": { - "type": "string" + "value": "[parameters('dnsConfigsRG')]" }, "privateEndpointPrivateLinkServiceId": { - "type": "string" + "value": "[parameters('privateEndpointPrivateLinkServiceId')]" }, "privateEndpointGroupId": { - "type": "string" + "value": "[parameters('privateEndpointGroupId')]" } }, - "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", + "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.", + "partial" + ], + "Microsoft.Cache/RedisEnterprise/redisEnterprise": [ + ".redis.azure.net", + ".redis.azure.net", + "full" + ] + } + }, + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2020-06-01", + "name": "[variables('getPECurrentProperties')]", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", "parameters": { "privateEndpointId": { - "type": "string" - } - }, - "outputs": { - "resource": { - "type": "object", - "value": "[reference(parameters('privateEndpointId'), '2024-10-01', 'Full')]" + "value": "[parameters('privateEndpointId')]" } }, - "resources": [] + "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]))) )]" + }, + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2020-06-01", + "dependsOn": [ + "[variables('getPECurrentProperties')]" + ], + "name": "[variables('deployPEDNSConfigs')]", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" }, - "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", + "mode": "Incremental", "parameters": { "privateEndpointName": { - "type": "string" + "value": "[parameters('privateEndpointName')]" }, "location": { - "type": "string" + "value": "[parameters('location')]" }, "customDnsConfigs": { - "type": "array" + "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', if(equals(tryGet(variables('mappings'), variables('mappedName'))[2], 'partial'), replace(lambdaVariables('dns').fqdn, tryGet(variables('mappings'), variables('mappedName'))[0], tryGet(variables('mappings'), variables('mappedName'))[1]), if(equals(tryGet(variables('mappings'), variables('mappedName'))[2], 'full'), tryGet(variables('mappings'), variables('mappedName'))[1], lambdaVariables('dns').fqdn)))))]" }, "dnsZoneGroupName": { - "type": "string" + "value": "[parameters('dnsZoneGroupName')]" }, "dnsConfigsRG": { - "type": "string" + "value": "[parameters('dnsConfigsRG')]" } }, - "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')], '.'))) ) ]" + "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" + } + }, + "variables": { + "customDnsConfigs": "[distinct(map(parameters('customDnsConfigs'), lambda('dns', substring(lambdaVariables('dns'), indexOf(lambdaVariables('dns'), '.'), sub(length(lambdaVariables('dns')), indexOf(lambdaVariables('dns'), '.'))))))]" + }, + "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(variables('customDnsConfigs'))]", + "input": { + "name": "[concat('privatelink', replace(variables('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')], '.', '-'))]", + "properties": { + "privateDnsZoneId": "[concat(parameters('dnsConfigsRG'), '/providers/Microsoft.Network/privateDnsZones/privatelink', variables('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." - } - } + }, + "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." + } + } } + } } \ No newline at end of file diff --git a/policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.rules.json b/policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.rules.json index 0da296b2..971f7a3e 100644 --- a/policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.rules.json +++ b/policyDefinitions/Network/configure-private-endpoint-to-use-private-dns-zones-generic/azurepolicy.rules.json @@ -1,227 +1,236 @@ { - "if": { - "allOf": [ - { - "field": "type", - "equals": "Microsoft.Network/privateEndpoints" + "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')]" + } + ] + } }, - { - "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 }, - "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[*]" }, - { - "count": { - "field": "Microsoft.Network/privateEndpoints/customDnsConfigs[*]" - }, - "equals": 0 + "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')]" } - ] - }, - "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": { "privateEndpointName": { - "value": "[field('name')]" + "type": "string" }, "privateEndpointId": { - "value": "[field('id')]" + "type": "string" }, "location": { - "value": "[field('location')]" + "type": "string" }, "dnsZoneGroupName": { - "value": "[parameters('dnsZoneGroupName')]" + "type": "string" }, "dnsConfigsRG": { - "value": "[parameters('dnsConfigsRG')]" + "type": "string" }, "privateEndpointPrivateLinkServiceId": { - "value": "[parameters('privateEndpointPrivateLinkServiceId')]" + "type": "string" }, "privateEndpointGroupId": { - "value": "[parameters('privateEndpointGroupId')]" + "type": "string" } }, - "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", + "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.", + "partial" + ], + "Microsoft.Cache/RedisEnterprise/redisEnterprise" : [ + ".redis.azure.net", + ".redis.azure.net", + "full" + ] + } + }, + "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": { - "value": "[parameters('privateEndpointId')]" + "type": "string" } }, - "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": [] - } + "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" + } + }, + { + "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')]" }, - "mode": "Incremental", + "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', if(equals(tryGet(variables('mappings'), variables('mappedName'))[2], 'partial'), replace(lambdaVariables('dns').fqdn, tryGet(variables('mappings'), variables('mappedName'))[0], tryGet(variables('mappings'), variables('mappedName'))[1]), if(equals(tryGet(variables('mappings'), variables('mappedName'))[2], 'full'), tryGet(variables('mappings'), variables('mappedName'))[1], lambdaVariables('dns').fqdn)))))]" + }, + "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": { - "value": "[parameters('privateEndpointName')]" + "type": "string" }, "location": { - "value": "[parameters('location')]" + "type": "string" }, "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]))) )]" + "type": "array" }, "dnsZoneGroupName": { - "value": "[parameters('dnsZoneGroupName')]" + "type": "string" }, "dnsConfigsRG": { - "value": "[parameters('dnsConfigsRG')]" + "type": "string" } }, - "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')], '.'))) ) ]" - } + "variables": { + "customDnsConfigs": "[distinct(map(parameters('customDnsConfigs'), lambda('dns', substring(lambdaVariables('dns'), indexOf(lambdaVariables('dns'), '.'), sub(length(lambdaVariables('dns')), indexOf(lambdaVariables('dns'), '.'))))))]" + }, + "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(variables('customDnsConfigs'))]", + "input": { + "name": "[concat('privatelink', replace(variables('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')], '.', '-'))]", + "properties": { + "privateDnsZoneId": "[concat(parameters('dnsConfigsRG'), '/providers/Microsoft.Network/privateDnsZones/privatelink', variables('customDnsConfigs')[copyIndex('privateDnsZoneConfigs')] ) ]" } } - ] - } + } + ] } - ] - } + } + ] } } - ] - } + } + ] } } } } - } \ No newline at end of file + } +} \ No newline at end of file