Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 2df02c8

Browse files
committed
cleanup vnet deployment in bicep
1 parent 8c56f7f commit 2df02c8

File tree

2 files changed

+89
-55
lines changed

2 files changed

+89
-55
lines changed

infra/core/vnet/vnet.bicep

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
@description('Name of the vnet resource.')
5+
param vnetName string
6+
7+
@description('Azure region where the resource will be deployed.')
8+
param location string = resourceGroup().location
9+
10+
@description('Optional prefix to prepend to subnet names.')
11+
param subnetPrefix string = 'snet-'
12+
13+
@description('APIM tier - used to determine if subnet delegations are required.')
14+
@allowed(['Developer', 'StandardV2'])
15+
param apimTier string
16+
17+
@description('NSG resource ID.')
18+
param nsgID string
19+
20+
resource vnet 'Microsoft.Network/virtualNetworks@2024-01-01' = {
21+
name: vnetName
22+
location: location
23+
properties: {
24+
addressSpace: {
25+
addressPrefixes: [
26+
'10.1.0.0/16'
27+
]
28+
}
29+
subnets: [
30+
{
31+
name: '${subnetPrefix}apim'
32+
properties: {
33+
addressPrefix: '10.1.0.0/24'
34+
networkSecurityGroup: {
35+
id: nsgID
36+
}
37+
delegations: (apimTier == 'Developer')
38+
? []
39+
: [
40+
{
41+
name: 'Microsoft.Web/serverFarms'
42+
properties: {
43+
serviceName: 'Microsoft.Web/serverFarms'
44+
}
45+
}
46+
]
47+
}
48+
}
49+
{
50+
name: '${subnetPrefix}aks'
51+
properties: {
52+
addressPrefix: '10.1.1.0/24'
53+
serviceEndpoints: [
54+
{
55+
service: 'Microsoft.Storage'
56+
}
57+
{
58+
service: 'Microsoft.Sql'
59+
}
60+
{
61+
service: 'Microsoft.EventHub'
62+
}
63+
]
64+
}
65+
}
66+
]
67+
}
68+
}
69+
70+
output vnetId string = vnet.id
71+
output vnetName string = vnet.name
72+
output apimSubnetId string = vnet.properties.subnets[0].id
73+
output aksSubnetId string = vnet.properties.subnets[1].id

infra/main.bicep

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -137,53 +137,14 @@ module nsg 'core/vnet/nsg.bicep' = {
137137
}
138138
}
139139

140-
resource vnet 'Microsoft.Network/virtualNetworks@2024-01-01' = {
141-
name: '${abbrs.networkVirtualNetworks}${resourceBaseNameFinal}-deployment'
142-
location: location
143-
properties: {
144-
addressSpace: {
145-
addressPrefixes: [
146-
'10.1.0.0/16'
147-
]
148-
}
149-
subnets: [
150-
{
151-
name: '${abbrs.networkVirtualNetworksSubnets}apim'
152-
properties: {
153-
addressPrefix: '10.1.0.0/24'
154-
networkSecurityGroup: {
155-
id: nsg.outputs.id
156-
}
157-
delegations: (apimTier == 'Developer')
158-
? []
159-
: [
160-
{
161-
name: 'Microsoft.Web/serverFarms'
162-
properties: {
163-
serviceName: 'Microsoft.Web/serverFarms'
164-
}
165-
}
166-
]
167-
}
168-
}
169-
{
170-
name: '${abbrs.networkVirtualNetworksSubnets}aks'
171-
properties: {
172-
addressPrefix: '10.1.1.0/24'
173-
serviceEndpoints: [
174-
{
175-
service: 'Microsoft.Storage'
176-
}
177-
{
178-
service: 'Microsoft.Sql'
179-
}
180-
{
181-
service: 'Microsoft.EventHub'
182-
}
183-
]
184-
}
185-
}
186-
]
140+
module vnet 'core/vnet/vnet.bicep' = {
141+
name: 'vnet-deployment'
142+
params: {
143+
vnetName: '${abbrs.networkVirtualNetworks}${resourceBaseNameFinal}'
144+
location: location
145+
subnetPrefix: abbrs.networkVirtualNetworksSubnets
146+
apimTier: apimTier
147+
nsgID: nsg.outputs.id
187148
}
188149
}
189150

@@ -204,7 +165,7 @@ module aks 'core/aks/aks.bicep' = {
204165
graphragIndexingVMSize: 'standard_e8s_v5' // 8 vcpus, 64 GB memory
205166
clusterAdmins: !empty(deployerPrincipalId) ? ['${deployerPrincipalId}'] : null
206167
logAnalyticsWorkspaceId: log.outputs.id
207-
subnetId: vnet.properties.subnets[1].id // aks subnet
168+
subnetId: vnet.outputs.aksSubnetId
208169
privateDnsZoneName: privateDnsZone.outputs.name
209170
}
210171
}
@@ -268,7 +229,7 @@ module apim 'core/apim/apim.bicep' = {
268229
availabilityZones: [] // TODO expose in param for premium sku
269230
publisherEmail: apiPublisherEmail
270231
publisherName: apiPublisherName
271-
subnetId: vnet.properties.subnets[0].id // apim subnet
232+
subnetId: vnet.outputs.apimSubnetId
272233
}
273234
}
274235

@@ -300,7 +261,7 @@ module privateDnsZone 'core/vnet/private-dns-zone.bicep' = {
300261
params: {
301262
name: dnsDomain
302263
vnetNames: [
303-
vnet.name
264+
vnet.outputs.vnetName // name
304265
]
305266
}
306267
}
@@ -309,7 +270,7 @@ module privatelinkPrivateDns 'core/vnet/privatelink-private-dns-zones.bicep' = i
309270
name: 'privatelink-private-dns-zones-deployment'
310271
params: {
311272
linkedVnetIds: [
312-
vnet.id
273+
vnet.outputs.vnetId // id
313274
]
314275
}
315276
}
@@ -331,7 +292,7 @@ module cosmosDbPrivateEndpoint 'core/vnet/private-endpoint.bicep' = if (enablePr
331292
privateEndpointName: '${abbrs.privateEndpoint}cosmos-${cosmosdb.outputs.name}'
332293
location: location
333294
privateLinkServiceId: cosmosdb.outputs.id
334-
subnetId: vnet.properties.subnets[1].id // aks subnet
295+
subnetId: vnet.outputs.aksSubnetId
335296
groupId: 'Sql'
336297
privateDnsZoneConfigs: enablePrivateEndpoints ? privatelinkPrivateDns.outputs.cosmosDbPrivateDnsZoneConfigs : []
337298
}
@@ -343,7 +304,7 @@ module blobStoragePrivateEndpoint 'core/vnet/private-endpoint.bicep' = if (enabl
343304
privateEndpointName: '${abbrs.privateEndpoint}blob-${storage.outputs.name}'
344305
location: location
345306
privateLinkServiceId: storage.outputs.id
346-
subnetId: vnet.properties.subnets[1].id // aks subnet
307+
subnetId: vnet.outputs.aksSubnetId
347308
groupId: 'blob'
348309
privateDnsZoneConfigs: enablePrivateEndpoints ? privatelinkPrivateDns.outputs.blobStoragePrivateDnsZoneConfigs : []
349310
}
@@ -355,7 +316,7 @@ module aiSearchPrivateEndpoint 'core/vnet/private-endpoint.bicep' = if (enablePr
355316
privateEndpointName: '${abbrs.privateEndpoint}search-${aiSearch.outputs.name}'
356317
location: location
357318
privateLinkServiceId: aiSearch.outputs.id
358-
subnetId: vnet.properties.subnets[1].id // aks subnet
319+
subnetId: vnet.outputs.aksSubnetId
359320
groupId: 'searchService'
360321
privateDnsZoneConfigs: enablePrivateEndpoints ? privatelinkPrivateDns.outputs.aiSearchPrivateDnsZoneConfigs : []
361322
}
@@ -367,7 +328,7 @@ module privateLinkScopePrivateEndpoint 'core/vnet/private-endpoint.bicep' = if (
367328
privateEndpointName: '${abbrs.privateEndpoint}pls-${resourceBaseNameFinal}'
368329
location: location
369330
privateLinkServiceId: enablePrivateEndpoints ? azureMonitorPrivateLinkScope.outputs.id : ''
370-
subnetId: vnet.properties.subnets[1].id // aks subnet
331+
subnetId: vnet.outputs.aksSubnetId
371332
groupId: 'azuremonitor'
372333
privateDnsZoneConfigs: enablePrivateEndpoints ? privatelinkPrivateDns.outputs.azureMonitorPrivateDnsZoneConfigs : []
373334
}

0 commit comments

Comments
 (0)