Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vnet and subnet support #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions infra/app/app-env.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ param serviceBusName string
param applicationInsightsName string = ''
param daprEnabled bool = false
param managedIdentityClientId string
param vnetInernal bool
param vnetName string

// Container apps host (including container registry)
module containerApps '../core/host/container-apps.bicep' = {
Expand All @@ -18,6 +20,8 @@ module containerApps '../core/host/container-apps.bicep' = {
logAnalyticsWorkspaceName: logAnalyticsWorkspaceName
applicationInsightsName: applicationInsightsName
daprEnabled: daprEnabled
vnetName: vnetName
vnetInternal: vnetInernal
}
}

Expand Down
12 changes: 12 additions & 0 deletions infra/core/host/container-apps-environment.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ param daprEnabled bool = false
@description('Name of the Log Analytics workspace')
param logAnalyticsWorkspaceName string

param vnetInternal bool = true
@description('Name of the Vnet')
param vnetName string

resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' = {
name: name
location: location
Expand All @@ -25,9 +29,17 @@ resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01'
}
}
daprAIInstrumentationKey: daprEnabled && !empty(applicationInsightsName) ? applicationInsights.properties.InstrumentationKey : ''
vnetConfiguration: {
infrastructureSubnetId: vnet.properties.subnets[0].id
internal: vnetInternal
}
}
}

resource vnet 'Microsoft.Network/virtualNetworks@2021-05-01' existing = {
name: vnetName
}

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = {
name: logAnalyticsWorkspaceName
}
Expand Down
4 changes: 4 additions & 0 deletions infra/core/host/container-apps.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ param containerRegistryAdminUserEnabled bool = false
param logAnalyticsWorkspaceName string
param applicationInsightsName string = ''
param daprEnabled bool = false
param vnetName string
param vnetInternal bool = true

module containerAppsEnvironment 'container-apps-environment.bicep' = {
name: '${name}-container-apps-environment'
Expand All @@ -20,6 +22,8 @@ module containerAppsEnvironment 'container-apps-environment.bicep' = {
logAnalyticsWorkspaceName: logAnalyticsWorkspaceName
applicationInsightsName: applicationInsightsName
daprEnabled: daprEnabled
vnetName: vnetName
vnetInternal: vnetInternal
}
}

Expand Down
30 changes: 30 additions & 0 deletions infra/core/networking/vnet.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
param location string
param vnetName string
param vnetPrefix string
param subnets array

resource vnet 'Microsoft.Network/virtualNetworks@2021-05-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
vnetPrefix
]
}
subnets: subnets
}
}

@batchSize(1)
resource vnetSubnets 'Microsoft.Network/virtualNetworks/subnets@2020-08-01' = [ for subnet in subnets: {
parent: vnet
name: '${subnet.name}'
properties: {
addressPrefix: subnet.properties.addressPrefix
privateEndpointNetworkPolicies: 'Disabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}]

output vnetName string = vnet.name
29 changes: 28 additions & 1 deletion infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ param resourceGroupName string = ''
// "resourceGroupName": {
// "value": "myGroupName"
// }
param vnetName string = 'vnet-ca'
param vnetInternal bool = true
param vnetPrefix string = '10.0.0.0/16'

var abbrs = loadJsonContent('./abbreviations.json')
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
Expand Down Expand Up @@ -80,7 +83,6 @@ module serviceBusAccess './app/access.bicep' = {
}
}


// Shared App Env with Dapr configuration for db
module appEnv './app/app-env.bicep' = {
name: 'app-env'
Expand All @@ -94,6 +96,31 @@ module appEnv './app/app-env.bicep' = {
applicationInsightsName: monitoring.outputs.applicationInsightsName
daprEnabled: true
managedIdentityClientId: serviceBusAccess.outputs.managedIdentityClientlId
vnetName: vnet.outputs.vnetName
vnetInernal: vnetInternal
}
}

var containerAppsSubnet = {
name: 'ContainerAppsSubnet'
properties: {
addressPrefix: '10.0.0.0/23'
}
}

var subnets = [
containerAppsSubnet
]

// Deploy an Azure Virtual Network
module vnet 'core/networking/vnet.bicep' = {
name: '${deployment().name}--vnet'
scope: rg
params: {
location: location
vnetName: vnetName
vnetPrefix: vnetPrefix
subnets: subnets
}
}

Expand Down
Loading