Skip to content

Commit b16fd31

Browse files
committed
Private endpoints draft
1 parent f33af14 commit b16fd31

File tree

3 files changed

+19
-36
lines changed

3 files changed

+19
-36
lines changed

infra/main.bicep

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ module backend 'core/host/appservice.bicep' = if (deploymentTarget == 'appservic
431431
appCommandLine: 'python3 -m gunicorn main:app'
432432
scmDoBuildDuringDeployment: true
433433
managedIdentity: true
434-
virtualNetworkSubnetId: isolation.outputs.appSubnetId
434+
virtualNetworkSubnetId: usePrivateEndpoint ? isolation.outputs.appSubnetId : ''
435435
publicNetworkAccess: publicNetworkAccess
436436
allowedOrigins: allowedOrigins
437437
clientAppId: clientAppId
@@ -472,6 +472,7 @@ module containerApps 'core/host/container-apps.bicep' = if (deploymentTarget ==
472472
containerAppsEnvironmentName: acaManagedEnvironmentName
473473
containerRegistryName: '${containerRegistryName}${resourceToken}'
474474
logAnalyticsWorkspaceResourceId: useApplicationInsights ? monitoring.outputs.logAnalyticsWorkspaceId : ''
475+
virtualNetworkSubnetId: usePrivateEndpoint ? isolation.outputs.appSubnetId : ''
475476
}
476477
}
477478

@@ -1047,17 +1048,15 @@ module cosmosDbRoleBackend 'core/security/documentdb-sql-role.bicep' = if (useAu
10471048
}
10481049
}
10491050

1050-
module isolation 'network-isolation.bicep' = {
1051+
module isolation 'network-isolation.bicep' = if (usePrivateEndpoint) {
10511052
name: 'networks'
10521053
scope: resourceGroup
10531054
params: {
1054-
deploymentTarget: deploymentTarget
10551055
location: location
10561056
tags: tags
10571057
vnetName: '${abbrs.virtualNetworks}${resourceToken}'
1058-
// Need to check deploymentTarget due to https://github.com/Azure/bicep/issues/3990
1059-
appServicePlanName: deploymentTarget == 'appservice' ? appServicePlan.outputs.name : ''
10601058
usePrivateEndpoint: usePrivateEndpoint
1059+
containerAppsEnvName: acaManagedEnvironmentName
10611060
}
10621061
}
10631062

@@ -1103,7 +1102,7 @@ var otherPrivateEndpointConnections = (usePrivateEndpoint && deploymentTarget ==
11031102

11041103
var privateEndpointConnections = concat(otherPrivateEndpointConnections, openAiPrivateEndpointConnection)
11051104

1106-
module privateEndpoints 'private-endpoints.bicep' = if (usePrivateEndpoint && deploymentTarget == 'appservice') {
1105+
module privateEndpoints 'private-endpoints.bicep' = if (usePrivateEndpoint) {
11071106
name: 'privateEndpoints'
11081107
scope: resourceGroup
11091108
params: {

infra/network-isolation.bicep

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ param location string = resourceGroup().location
99
@description('The tags to apply to all resources')
1010
param tags object = {}
1111

12-
@description('The name of an existing App Service Plan to connect to the VNet')
13-
param appServicePlanName string
14-
1512
param usePrivateEndpoint bool = false
1613

17-
@allowed(['appservice', 'containerapps'])
18-
param deploymentTarget string
14+
param containerAppsEnvName string
1915

20-
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' existing = if (deploymentTarget == 'appservice') {
21-
name: appServicePlanName
16+
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = {
17+
name: containerAppsEnvName
2218
}
2319

20+
2421
module vnet './core/networking/vnet.bicep' = if (usePrivateEndpoint) {
2522
name: 'vnet'
2623
params: {
@@ -36,42 +33,28 @@ module vnet './core/networking/vnet.bicep' = if (usePrivateEndpoint) {
3633
privateLinkServiceNetworkPolicies: 'Enabled'
3734
}
3835
}
39-
{
40-
name: 'AzureBastionSubnet'
41-
properties: {
42-
addressPrefix: '10.0.2.0/24'
43-
privateEndpointNetworkPolicies: 'Enabled'
44-
privateLinkServiceNetworkPolicies: 'Enabled'
45-
}
46-
}
47-
{
36+
{ // App Service / Container Apps specific subnet
4837
name: 'app-int-subnet'
4938
properties: {
50-
addressPrefix: '10.0.3.0/24'
39+
addressPrefix: '10.0.4.0/23'
5140
privateEndpointNetworkPolicies: 'Enabled'
5241
privateLinkServiceNetworkPolicies: 'Enabled'
5342
delegations: [
5443
{
55-
id: appServicePlan.id
56-
name: appServicePlan.name
44+
id: containerAppsEnvironment.id
45+
name: containerAppsEnvironment.name
5746
properties: {
58-
serviceName: 'Microsoft.Web/serverFarms'
47+
serviceName: 'Microsoft.App/environments'
5948
}
6049
}
6150
]
6251
}
6352
}
64-
{
65-
name: 'vm-subnet'
66-
properties: {
67-
addressPrefix: '10.0.4.0/24'
68-
}
69-
}
7053
]
7154
}
7255
}
7356

7457

75-
output appSubnetId string = usePrivateEndpoint ? vnet.outputs.vnetSubnets[2].id : ''
58+
output appSubnetId string = usePrivateEndpoint ? vnet.outputs.vnetSubnets[1].id : ''
7659
output backendSubnetId string = usePrivateEndpoint ? vnet.outputs.vnetSubnets[0].id : ''
7760
output vnetName string = usePrivateEndpoint ? vnet.outputs.name : ''

infra/private-endpoints.bicep

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ module monitorDnsZones './core/networking/private-dns-zones.bicep' = [for monito
8181
}
8282
}]
8383
// Get blob DNS zone index for monitor private link
84-
var dnsZoneBlobIndex = filter(flatten(privateEndpointInfo), info => info.groupId == 'blob')[0].dnsZoneIndex
84+
var blobEndpointInfo = filter(flatten(privateEndpointInfo), info => info.groupId == 'blob')
85+
var dnsZoneBlobIndex = empty(blobEndpointInfo) ? 0 : blobEndpointInfo[0].dnsZoneIndex
8586

8687
// Azure Monitor Private Link Scope
8788
// https://learn.microsoft.com/azure/azure-monitor/logs/private-link-security
@@ -150,9 +151,9 @@ module monitorPrivateEndpoint './core/networking/private-endpoint.bicep' = {
150151
}
151152
}
152153
{
153-
name: dnsZones[dnsZoneBlobIndex].name
154+
name: 'blob-dnszone' // dnsZones[dnsZoneBlobIndex].name
154155
properties: {
155-
privateDnsZoneId: dnsZones[dnsZoneBlobIndex].outputs.id
156+
privateDnsZoneId: '/subscriptions/77d8a3d0-8b18-47e9-b773-08bee327bb4a/resourceGroups/rg-pf-ragprivate/providers/Microsoft.Network/privateDnsZones/privatelink.blob.core.windows.net' // dnsZones[dnsZoneBlobIndex].outputs.id
156157
}
157158
}
158159
]

0 commit comments

Comments
 (0)