Skip to content

Commit

Permalink
feat: Add Nat Gateway for outbound access in OCPP server infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
jmservera committed Jul 26, 2024
1 parent 1783978 commit 4112a3f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ocpp-server/infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ param pubSubHubName string = 'OcppService'
var pubsubHostName = '${pubsubARecordName}.${customDnsZoneName}'
var webHostName = '${webARecordName}.${customDnsZoneName}'

// Add a Nat Gateway for outbound access
module natgw './modules/natgw.bicep' = {
name: 'natGwService'
params: {
natGwName: 'natgw-${uniqueString(resourceGroup().id)}'
location: resourceGroup().location
}
}
// Creates a VNet with 3 subnets: default, gateway and private endpoints
module virtualNetwork './modules/virtualNetwork.bicep' = {
name: 'vNet'
params: {
virtualNetworkName: 'vnet-${uniqueString(resourceGroup().id)}'
natGatewayId: natgw.outputs.natGatewayId
}
}

Expand Down
34 changes: 34 additions & 0 deletions ocpp-server/infra/modules/natgw.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
param natGwName string
param sku string = 'Standard'
param tier string = 'Regional'
param idleTimeoutInMinutes int = 4
param location string = resourceGroup().location

resource publicIpPrefixes 'Microsoft.Network/publicIPPrefixes@2023-11-01' = {
name: 'ipPrefixes-${natGwName}'
location: location
sku: {
name: sku
tier: tier
}
properties: {
prefixLength: 28
publicIPAddressVersion: 'IPv4'
natGateway: {
id: natGateway.id
}
}
}

resource natGateway 'Microsoft.Network/natGateways@2023-11-01' = {
name: natGwName
location: location
sku: {
name: sku
}
properties: {
idleTimeoutInMinutes: idleTimeoutInMinutes
}
}

output natGatewayId string = natGateway.id
12 changes: 11 additions & 1 deletion ocpp-server/infra/modules/virtualNetwork.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ param privateSubnetName string = 'private-endpoints'
param privateSubnetPrefix string = '10.1.1.0/24'
param gatewaySubnetName string = 'gateway'
param gatewaySubnetPrefix string = '10.1.2.0/24'
param natGatewayId string

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-09-01' = {
name: virtualNetworkName
Expand All @@ -20,25 +21,34 @@ resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-09-01' = {
name: subnetName
properties: {
addressPrefix: subnetPrefix
natGateway: {
id: natGatewayId
}
delegations: [
{
name: 'Microsoft.Web/serverFarms'
properties: {
serviceName: 'Microsoft.Web/serverFarms'
}
}
]
]
}
}
{
name: privateSubnetName
properties: {
natGateway: {
id: natGatewayId
}
addressPrefix: privateSubnetPrefix
}
}
{
name: gatewaySubnetName
properties: {
natGateway: {
id: natGatewayId
}
addressPrefix: gatewaySubnetPrefix
}
}
Expand Down

0 comments on commit 4112a3f

Please sign in to comment.