Skip to content

Commit

Permalink
Refactor private endpoint module, add static endpointconfig, to reduc…
Browse files Browse the repository at this point in the history
…e need for copy and paste of DNS Zone names
  • Loading branch information
janboll committed Nov 5, 2024
1 parent 6322ba2 commit 2bd9fbd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
32 changes: 24 additions & 8 deletions dev-infrastructure/modules/private-endpoint.bicep
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
param location string

@description('The service type the private endpoint is created for')
@allowed([
'eventgrid'
])
param serviceType string
param subnetIds array

param privateLinkServiceId string
@description('The group id of the private endpoint service')
@allowed([
'topicspace'
])
param groupId string

param groupIds array
@description('The private link service id')
param privateLinkServiceId string

param privateEndpointDnsZoneName string
@description('The subnet ids to create the private endpoint in')
param subnetIds array

@description('The vnet id to link the private endpoint to')
param vnetId string

var endpointConfig = {
eventgrid: {
topicspace: 'privatelink.ts.eventgrid.azure.net'
}
}

resource eventGridPrivateEndpointDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
name: privateEndpointDnsZoneName
name: endpointConfig[serviceType][groupId]
location: 'global'
properties: {}
}

resource eventGridPrivatEndpoint 'Microsoft.Network/privateEndpoints@2023-09-01' = [
resource privatEndpoint 'Microsoft.Network/privateEndpoints@2023-09-01' = [
for aksNodeSubnetId in subnetIds: {
name: '${serviceType}-${uniqueString(aksNodeSubnetId)}'
location: location
Expand All @@ -27,7 +43,7 @@ resource eventGridPrivatEndpoint 'Microsoft.Network/privateEndpoints@2023-09-01'
name: '${serviceType}-private-endpoint'
properties: {
privateLinkServiceId: privateLinkServiceId
groupIds: groupIds
groupIds: [groupId]
}
}
]
Expand All @@ -41,7 +57,7 @@ resource eventGridPrivatEndpoint 'Microsoft.Network/privateEndpoints@2023-09-01'
resource privateEndpointDnsGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2023-09-01' = [
for index in range(0, length(subnetIds)): {
name: '${serviceType}-${uniqueString(subnetIds[index])}'
parent: eventGridPrivatEndpoint[index]
parent: privatEndpoint[index]
properties: {
privateDnsZoneConfigs: [
{
Expand Down
5 changes: 2 additions & 3 deletions dev-infrastructure/templates/mgmt-cluster.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ module eventGrindPrivateEndpoint '../modules/private-endpoint.bicep' = {
name: 'eventGridPrivateEndpoint'
params: {
location: location
serviceType: 'eventgrid'
subnetIds: [mgmtCluster.outputs.aksNodeSubnetId]
privateLinkServiceId: eventGridNamespace.id
groupIds: ['topicspace']
privateEndpointDnsZoneName: 'privatelink.ts.eventgrid.azure.net'
vnetId: mgmtCluster.outputs.aksVnetId
serviceType: 'eventgrid'
groupId: 'topicspace'
}
}
5 changes: 2 additions & 3 deletions dev-infrastructure/templates/svc-cluster.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,10 @@ module eventGrindPrivateEndpoint '../modules/private-endpoint.bicep' = {
name: 'eventGridPrivateEndpoint'
params: {
location: location
serviceType: 'eventgrid'
subnetIds: [svcCluster.outputs.aksNodeSubnetId]
privateLinkServiceId: eventGridNamespace.id
groupIds: ['topicspace']
privateEndpointDnsZoneName: 'privatelink.ts.eventgrid.azure.net'
serviceType: 'eventgrid'
groupId: 'topicspace'
vnetId: svcCluster.outputs.aksVnetId
}
}

0 comments on commit 2bd9fbd

Please sign in to comment.