-
Notifications
You must be signed in to change notification settings - Fork 1
/
privateEndpoint.bicep
73 lines (68 loc) · 1.94 KB
/
privateEndpoint.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@description('The region in which to create the new instance, defaults to the same location as the resource group.')
param location string = resourceGroup().location
param endpointName string = 'privateep${uniqueString(resourceGroup().id)}'
param vnetId string
param subnetId string
@description('The resource id of the resource to link with this private link.')
param privateLinkResource string
@allowed([
'webpubsub'
'sites'
'blob'
])
param targetSubResource string
var dnsByTarget = {
webpubsub: 'privatelink.webpubsub.azure.com'
sites: 'privatelink.azurewebsites.net'
blob: 'privatelink.blob.${environment().suffixes.storage}'
}
resource privateEndpoint 'Microsoft.Network/privateEndpoints@2021-05-01' = {
location: location
name: endpointName
properties: {
subnet: {
id: subnetId
}
customNetworkInterfaceName: '${endpointName}-nic'
privateLinkServiceConnections: [
{
name: endpointName
properties: {
privateLinkServiceId: privateLinkResource
groupIds: [targetSubResource]
}
}
]
}
}
resource privateDnsZone 'Microsoft.Network/privateDnsZones@2018-09-01' = {
// it is important to set the right location
// https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-dns
name: dnsByTarget[targetSubResource]
location: 'global'
}
resource virtualNetworkLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = {
name: '${endpointName}-link'
location: 'global'
parent: privateDnsZone
properties: {
registrationEnabled: false
virtualNetwork: {
id: vnetId
}
}
}
resource privateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2023-11-01' = {
name: '${endpointName}-group'
parent: privateEndpoint
properties: {
privateDnsZoneConfigs: [
{
name: 'privatelink-${endpointName}'
properties: {
privateDnsZoneId: privateDnsZone.id
}
}
]
}
}