Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build and deploy AI applications on Azure AI Foundry using Microsoft's model catalog and AI services
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
resource/private-network/references/vpn-dns-setup.bicep
1/*2VPN Gateway + DNS Private Resolver3------------------------------------4Post-deployment add-on for private network templates (T10, T15–T19).5Creates a P2S VPN Gateway (AAD auth, OpenVPN) and a DNS Private Resolver6so the user can connect from their dev machine and resolve private DNS zones.78Note: VPN Gateway deployment takes 30-45 minutes.9*/1011@description('Name of the existing VNet from the Foundry deployment')12param vnetName string1314@description('Resource group of the existing VNet. Defaults to the deployment resource group.')15param vnetResourceGroup string = resourceGroup().name1617// ── Existing VNet ──18resource vnet 'Microsoft.Network/virtualNetworks@2024-05-01' existing = {19name: vnetName20scope: resourceGroup(vnetResourceGroup)21}2223var location = vnet.location2425@description('CIDR for GatewaySubnet — agent must compute from available VNet space')26param gatewaySubnetCidr string2728@description('CIDR for DNS resolver inbound subnet — agent must compute from available VNet space')29param dnsResolverSubnetCidr string3031@description('VPN client address pool — must not overlap with VNet')32param vpnClientAddressPool string = '172.16.201.0/24'3334@description('Azure AD tenant ID for VPN authentication')35param aadTenantId string3637@description('Unique suffix for resource naming')38param suffix string3940// AAD constants for Azure Public cloud only.41// Sovereign clouds (AzureUSGovernment, AzureChinaCloud) require different audience/issuer values.42// The intake step (az cloud show) warns users before reaching this template.43var aadAudience = 'c632b3df-fb67-4d84-bdcf-b95ad541b5c8'44var aadIssuer = 'https://sts.windows.net/${aadTenantId}/'45var aadTenant = 'https://login.microsoftonline.com/${aadTenantId}/'4647// ── Add subnets ──48resource gatewaySubnet 'Microsoft.Network/virtualNetworks/subnets@2024-05-01' = {49parent: vnet50name: 'GatewaySubnet'51properties: {52addressPrefix: gatewaySubnetCidr53defaultOutboundAccess: false54}55}5657// NOTE: NRMS policy may auto-deploy an NSG on this subnet.58// Ensure the NSG allows inbound UDP/TCP port 53 (DNS) from the VPN client address pool.59resource dnsResolverSubnet 'Microsoft.Network/virtualNetworks/subnets@2024-05-01' = {60parent: vnet61name: 'dns-resolver-inbound'62properties: {63addressPrefix: dnsResolverSubnetCidr64defaultOutboundAccess: false65delegations: [66{67name: 'dns-resolver-delegation'68properties: {69serviceName: 'Microsoft.Network/dnsResolvers'70}71}72]73}74dependsOn: [gatewaySubnet] // serialize subnet updates75}7677// ── Public IP for VPN Gateway ──78resource vpnGatewayPip 'Microsoft.Network/publicIPAddresses@2024-05-01' = {79name: 'vpn-gateway-pip-${suffix}'80location: location81sku: {82name: 'Standard'83}84zones: ['1', '2', '3']85properties: {86publicIPAllocationMethod: 'Static'87}88}8990// ── VPN Gateway ──91resource vpnGateway 'Microsoft.Network/virtualNetworkGateways@2024-05-01' = {92name: 'vpn-gateway-${suffix}'93location: location94properties: {95gatewayType: 'Vpn'96vpnType: 'RouteBased'97sku: {98name: 'VpnGw1AZ'99tier: 'VpnGw1AZ'100}101ipConfigurations: [102{103name: 'default'104properties: {105publicIPAddress: {106id: vpnGatewayPip.id107}108subnet: {109id: gatewaySubnet.id110}111}112}113]114vpnClientConfiguration: {115vpnClientAddressPool: {116addressPrefixes: [vpnClientAddressPool]117}118vpnClientProtocols: ['OpenVPN']119vpnAuthenticationTypes: ['AAD']120aadTenant: aadTenant121aadAudience: aadAudience122aadIssuer: aadIssuer123}124}125}126127// ── DNS Private Resolver ──128resource dnsResolver 'Microsoft.Network/dnsResolvers@2022-07-01' = {129name: 'dns-resolver-${suffix}'130location: location131properties: {132virtualNetwork: {133id: vnet.id134}135}136}137138resource dnsInboundEndpoint 'Microsoft.Network/dnsResolvers/inboundEndpoints@2022-07-01' = {139parent: dnsResolver140name: 'inbound'141location: location142properties: {143ipConfigurations: [144{145privateIpAllocationMethod: 'Dynamic'146subnet: {147id: dnsResolverSubnet.id148}149}150]151}152}153154// ── Outputs ──155output vpnGatewayName string = vpnGateway.name156output vpnGatewayId string = vpnGateway.id157output vpnPublicIpAddress string = vpnGatewayPip.properties.ipAddress158output dnsResolverInboundIp string = dnsInboundEndpoint.properties.ipConfigurations[0].privateIpAddress159