Skip to content

Commit d1ea8eb

Browse files
Nicholas GreenfieldNicholas Greenfield
authored andcommitted
Add vnet support
1 parent e9eb972 commit d1ea8eb

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

infra/app/app-env.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ param location string
44
param logAnalyticsWorkspaceName string
55
param applicationInsightsName string
66
param daprEnabled bool
7+
param vnetName string
78

89
// Container apps host (including container registry)
910
module containerApps '../core/host/container-apps.bicep' = {
@@ -16,6 +17,7 @@ module containerApps '../core/host/container-apps.bicep' = {
1617
logAnalyticsWorkspaceName: logAnalyticsWorkspaceName
1718
applicationInsightsName: applicationInsightsName
1819
daprEnabled: daprEnabled
20+
vnetName: vnetName
1921
}
2022
}
2123

infra/core/host/container-apps-environment.bicep

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ param logAnalyticsWorkspaceName string
66
param applicationInsightsName string = ''
77
param daprEnabled bool = false
88

9+
@description('Name of the Vnet')
10+
param vnetName string
11+
912
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' = {
1013
name: name
1114
location: location
@@ -19,9 +22,16 @@ resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01'
1922
}
2023
}
2124
daprAIInstrumentationKey: daprEnabled && applicationInsightsName != '' ? applicationInsights.properties.InstrumentationKey : ''
25+
vnetConfiguration: {
26+
infrastructureSubnetId: vnet.properties.subnets[0].id
27+
}
2228
}
2329
}
2430

31+
resource vnet 'Microsoft.Network/virtualNetworks@2021-05-01' existing = {
32+
name: vnetName
33+
}
34+
2535
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = {
2636
name: logAnalyticsWorkspaceName
2737
}

infra/core/host/container-apps.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ param containerRegistryName string = ''
77
param logAnalyticsWorkspaceName string = ''
88
param applicationInsightsName string = ''
99
param daprEnabled bool = false
10+
param vnetName string
1011

1112
module containerAppsEnvironment 'container-apps-environment.bicep' = {
1213
name: '${name}-container-apps-environment'
@@ -17,6 +18,7 @@ module containerAppsEnvironment 'container-apps-environment.bicep' = {
1718
logAnalyticsWorkspaceName: logAnalyticsWorkspaceName
1819
applicationInsightsName: applicationInsightsName
1920
daprEnabled: daprEnabled
21+
vnetName: vnetName
2022
}
2123
}
2224

infra/core/networking/vnet.bicep

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
param location string
2+
param vnetName string
3+
param vnetPrefix string
4+
param subnets array
5+
6+
resource vnet 'Microsoft.Network/virtualNetworks@2021-05-01' = {
7+
name: vnetName
8+
location: location
9+
properties: {
10+
addressSpace: {
11+
addressPrefixes: [
12+
vnetPrefix
13+
]
14+
}
15+
subnets: subnets
16+
}
17+
}
18+
19+
@batchSize(1)
20+
resource vnetSubnets 'Microsoft.Network/virtualNetworks/subnets@2020-08-01' = [ for subnet in subnets: {
21+
parent: vnet
22+
name: '${subnet.name}'
23+
properties: {
24+
addressPrefix: subnet.properties.addressPrefix
25+
privateEndpointNetworkPolicies: 'Disabled'
26+
privateLinkServiceNetworkPolicies: 'Enabled'
27+
}
28+
}]
29+
30+
output vnetName string = vnet.name

infra/main.bicep

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ param workerImageName string = ''
3939
var abbrs = loadJsonContent('./abbreviations.json')
4040
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
4141
var tags = { 'azd-env-name': environmentName }
42+
param vnetName string = 'vnet-ca'
43+
param vnetPrefix string = '10.0.0.0/16'
4244

4345
// Organize resources in a resource group
4446
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
@@ -58,6 +60,29 @@ module appEnv './app/app-env.bicep' = {
5860
logAnalyticsWorkspaceName: monitoring.outputs.logAnalyticsWorkspaceName
5961
applicationInsightsName: monitoring.outputs.applicationInsightsName
6062
daprEnabled: true
63+
vnetName: vnet.outputs.vnetName
64+
}
65+
}
66+
var containerAppsSubnet = {
67+
name: 'ContainerAppsSubnet'
68+
properties: {
69+
addressPrefix: '10.0.0.0/23'
70+
}
71+
}
72+
73+
var subnets = [
74+
containerAppsSubnet
75+
]
76+
77+
// Deploy an Azure Virtual Network
78+
module vnet 'core/networking/vnet.bicep' = {
79+
name: '${deployment().name}--vnet'
80+
scope: rg
81+
params: {
82+
location: location
83+
vnetName: vnetName
84+
vnetPrefix: vnetPrefix
85+
subnets: subnets
6186
}
6287
}
6388

0 commit comments

Comments
 (0)