Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ param virtualNetworkName string
@description('Required. The name of the Managed Identity to create.')
param managedIdentityName string

@description('Required. The name of the Local Network Gateway to create.')
param localNetworkGatewayName string

var addressPrefix = '10.0.0.0/16'

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2022-01-01' = {
Expand Down Expand Up @@ -34,8 +37,24 @@ resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-
location: location
}

resource localNetworkGateway 'Microsoft.Network/localNetworkGateways@2022-07-01' = {
name: localNetworkGatewayName
location: location
properties: {
gatewayIpAddress: '100.100.100.100'
localNetworkAddressSpace: {
addressPrefixes: [
'192.168.0.0/24'
]
}
}
}

@description('The resource ID of the created Virtual Network.')
output vnetResourceId string = virtualNetwork.id

@description('The principal ID of the created Managed Identity.')
output managedIdentityPrincipalId string = managedIdentity.properties.principalId

@description('The resource ID of the created Local Network Gateway.')
output localNetworkGatewayResourceId string = localNetworkGateway.id
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module nestedDependencies 'dependencies.bicep' = {
params: {
virtualNetworkName: 'dep-<<namePrefix>>-vnet-${serviceShort}'
managedIdentityName: 'dep-<<namePrefix>>-msi-${serviceShort}'
localNetworkGatewayName: 'dep-<<namePrefix>>-lng-${serviceShort}'
}
}

Expand Down Expand Up @@ -61,7 +62,7 @@ module testDeployment '../../deploy.bicep' = {
params: {
enableDefaultTelemetry: enableDefaultTelemetry
name: '<<namePrefix>>${serviceShort}001'
virtualNetworkGatewaySku: 'VpnGw1AZ'
virtualNetworkGatewaySku: 'VpnGw2AZ'
virtualNetworkGatewayType: 'Vpn'
vNetResourceId: nestedDependencies.outputs.vnetResourceId
activeActive: true
Expand All @@ -86,5 +87,44 @@ module testDeployment '../../deploy.bicep' = {
}
]
vpnType: 'RouteBased'
enablePrivateIpAddress: true
gatewayDefaultSiteLocalNetworkGatewayId: nestedDependencies.outputs.localNetworkGatewayResourceId
disableIPSecReplayProtection: true
allowRemoteVnetTraffic: true
natRules: [
{
name: 'nat-rule-1-static-IngressSnat'
type: 'Static'
mode: 'IngressSnat'
internalMappings: [
{
addressSpace: '10.100.0.0/24'
portRange: '100'
}
]
externalMappings: [
{
addressSpace: '192.168.0.0/24'
portRange: '100'
}
]
}
{
name: 'nat-rule-2-dynamic-EgressSnat'
type: 'Dynamic'
mode: 'EgressSnat'
internalMappings: [
{
addressSpace: '172.16.0.0/26'
}
]
externalMappings: [
{
addressSpace: '10.200.0.0/26'
}
]
}
]
enableBgpRouteTranslationForNat: true
}
}
51 changes: 49 additions & 2 deletions modules/Microsoft.Network/virtualNetworkGateways/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ param asn int = 65815
@description('Optional. The IP address range from which VPN clients will receive an IP address when connected. Range specified must not overlap with on-premise network.')
param vpnClientAddressPoolPrefix string = ''

@description('Optional. Configures this gateway to accept traffic from remote Virtual WAN networks.')
param allowVirtualWanTraffic bool = false

@description('Optional. Configure this gateway to accept traffic from other Azure Virtual Networks. This configuration does not support connectivity to Azure Virtual WAN.')
param allowRemoteVnetTraffic bool = false

@description('Optional. disableIPSecReplayProtection flag. Used for VPN Gateways.')
param disableIPSecReplayProtection bool = false

@description('Optional. Whether DNS forwarding is enabled or not and is only supported for Express Route Gateways. The DNS forwarding feature flag must be enabled on the current subscription.')
param enableDnsForwarding bool = false

@description('Optional. Whether private IP needs to be enabled on this gateway for connections or not. Used for configuring a Site-to-Site VPN connection over ExpressRoute private peering.')
param enablePrivateIpAddress bool = false

@description('Optional. The reference to the LocalNetworkGateway resource which represents local network site having default routes. Assign Null value in case of removing existing default site setting.')
param gatewayDefaultSiteLocalNetworkGatewayId string = ''

@description('Optional. NatRules for virtual network gateway. NAT is supported on the the following SKUs: VpnGw2~5, VpnGw2AZ~5AZ and is supported for IPsec/IKE cross-premises connections only.')
param natRules array = []

@description('Optional. EnableBgpRouteTranslationForNat flag. Can only be used when "natRules" are enabled on the Virtual Network Gateway.')
param enableBgpRouteTranslationForNat bool = false

@description('Optional. Client root certificate data used to authenticate VPN clients. Cannot be configured if vpnClientAadConfiguration is provided.')
param clientRootCertData string = ''

Expand Down Expand Up @@ -335,20 +359,29 @@ module publicIPAddress '../publicIPAddresses/deploy.bicep' = [for (virtualGatewa

// VNET Gateway
// ============
resource virtualNetworkGateway 'Microsoft.Network/virtualNetworkGateways@2021-08-01' = {
resource virtualNetworkGateway 'Microsoft.Network/virtualNetworkGateways@2022-07-01' = {
name: name
location: location
tags: tags
properties: {
ipConfigurations: ipConfiguration
activeActive: isActiveActiveValid
allowRemoteVnetTraffic: allowRemoteVnetTraffic
allowVirtualWanTraffic: allowVirtualWanTraffic
enableBgp: isBgpValid
bgpSettings: isBgpValid ? bgpSettings : null
disableIPSecReplayProtection: disableIPSecReplayProtection
enableDnsForwarding: virtualNetworkGatewayType == 'ExpressRoute' ? enableDnsForwarding : null
enablePrivateIpAddress: enablePrivateIpAddress
enableBgpRouteTranslationForNat: enableBgpRouteTranslationForNat
gatewayType: virtualNetworkGatewayType
gatewayDefaultSite: !empty(gatewayDefaultSiteLocalNetworkGatewayId) ? {
id: gatewayDefaultSiteLocalNetworkGatewayId
} : null
sku: {
name: virtualNetworkGatewaySku
tier: virtualNetworkGatewaySku
}
gatewayType: virtualNetworkGatewayType
vpnType: vpnTypeVar
vpnClientConfiguration: !empty(vpnClientAddressPoolPrefix) ? vpnClientConfiguration : null
}
Expand All @@ -357,6 +390,20 @@ resource virtualNetworkGateway 'Microsoft.Network/virtualNetworkGateways@2021-08
]
}

module virtualNetworkGateway_natRules 'natRules/deploy.bicep' = [for (natRule, index) in natRules: {
name: '${deployment().name}-NATRule-${index}'
params: {
name: natRule.name
virtualNetworkGatewayName: virtualNetworkGateway.name
externalMappings: contains(natRule, 'externalMappings') ? natRule.externalMappings : []
internalMappings: contains(natRule, 'internalMappings') ? natRule.internalMappings : []
ipConfigurationId: contains(natRule, 'ipConfigurationId') ? natRule.ipConfigurationId : ''
mode: contains(natRule, 'mode') ? natRule.mode : ''
type: contains(natRule, 'type') ? natRule.type : ''
enableDefaultTelemetry: enableReferencedModulesTelemetry
}
}]

resource virtualNetworkGateway_lock 'Microsoft.Authorization/locks@2020-05-01' = if (!empty(lock)) {
name: '${virtualNetworkGateway.name}-${lock}-lock'
properties: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@description('Required. The name of the NAT rule.')
param name string

@description('Conditional. The name of the parent Virtual Network Gateway this NAT rule is associated with. Required if the template is used in a standalone deployment.')
param virtualNetworkGatewayName string

@description('Optional. An address prefix range of destination IPs on the outside network that source IPs will be mapped to. In other words, your post-NAT address prefix range.')
param externalMappings array = []

@description('Optional. An address prefix range of source IPs on the inside network that will be mapped to a set of external IPs. In other words, your pre-NAT address prefix range.')
param internalMappings array = []

@description('Optional. A NAT rule must be configured to a specific Virtual Network Gateway instance. This is applicable to Dynamic NAT only. Static NAT rules are automatically applied to both Virtual Network Gateway instances.')
param ipConfigurationId string = ''

@description('Optional. The type of NAT rule for Virtual Network NAT. IngressSnat mode (also known as Ingress Source NAT) is applicable to traffic entering the Azure hub\'s site-to-site Virtual Network gateway. EgressSnat mode (also known as Egress Source NAT) is applicable to traffic leaving the Azure hub\'s Site-to-site Virtual Network gateway.')
@allowed([
''
'EgressSnat'
'IngressSnat'
])
param mode string = ''

@description('Optional. The type of NAT rule for Virtual Network NAT. Static one-to-one NAT establishes a one-to-one relationship between an internal address and an external address while Dynamic NAT assigns an IP and port based on availability.')
@allowed([
''
'Dynamic'
'Static'
])
param type string = ''

@description('Optional. Enable telemetry via a Globally Unique Identifier (GUID).')
param enableDefaultTelemetry bool = true

resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
}
}
}

resource virtualNetworkGateway 'Microsoft.Network/virtualNetworkGateways@2022-07-01' existing = {
name: virtualNetworkGatewayName
}

resource natRule 'Microsoft.Network/virtualNetworkGateways/natRules@2022-07-01' = {
name: name
parent: virtualNetworkGateway
properties: {
externalMappings: externalMappings
internalMappings: internalMappings
ipConfigurationId: !empty(ipConfigurationId) ? ipConfigurationId : null
mode: !empty(mode) ? any(mode) : null
type: !empty(type) ? any(type) : null
}
}

@description('The name of the NAT rule.')
output name string = natRule.name

@description('The resource ID of the NAT rule.')
output resourceId string = natRule.id

@description('The name of the resource group the NAT rule was deployed into.')
output resourceGroupName string = resourceGroup().name
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# VPN Gateways NATRules `[Microsoft.Network/virtualNetworkGateways/natRules]`

This module deploys Virtual Network Gateways NATRules

## Navigation

- [Resource Types](#Resource-Types)
- [Parameters](#Parameters)
- [Outputs](#Outputs)
- [Cross-referenced modules](#Cross-referenced-modules)

## Resource Types

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Network/virtualNetworkGateways/natRules` | [2022-07-01](https://docs.microsoft.com/en-us/azure/templates/Microsoft.Network/2022-07-01/virtualNetworkGateways/natRules) |

## Parameters

**Required parameters**

| Parameter Name | Type | Description |
| :-- | :-- | :-- |
| `name` | string | The name of the NAT rule. |

**Conditional parameters**

| Parameter Name | Type | Description |
| :-- | :-- | :-- |
| `virtualNetworkGatewayName` | string | The name of the parent Virtual Network Gateway this NAT rule is associated with. Required if the template is used in a standalone deployment. |

**Optional parameters**

| Parameter Name | Type | Default Value | Allowed Values | Description |
| :-- | :-- | :-- | :-- | :-- |
| `enableDefaultTelemetry` | bool | `True` | | Enable telemetry via a Globally Unique Identifier (GUID). |
| `externalMappings` | array | `[]` | | An address prefix range of destination IPs on the outside network that source IPs will be mapped to. In other words, your post-NAT address prefix range. |
| `internalMappings` | array | `[]` | | An address prefix range of source IPs on the inside network that will be mapped to a set of external IPs. In other words, your pre-NAT address prefix range. |
| `ipConfigurationId` | string | `''` | | A NAT rule must be configured to a specific Virtual Network Gateway instance. This is applicable to Dynamic NAT only. Static NAT rules are automatically applied to both Virtual Network Gateway instances. |
| `mode` | string | `''` | `['', EgressSnat, IngressSnat]` | The type of NAT rule for Virtual Network NAT. IngressSnat mode (also known as Ingress Source NAT) is applicable to traffic entering the Azure hub's site-to-site Virtual Network gateway. EgressSnat mode (also known as Egress Source NAT) is applicable to traffic leaving the Azure hub's Site-to-site Virtual Network gateway. |
| `type` | string | `''` | `['', Dynamic, Static]` | The type of NAT rule for Virtual Network NAT. Static one-to-one NAT establishes a one-to-one relationship between an internal address and an external address while Dynamic NAT assigns an IP and port based on availability. |


## Outputs

| Output Name | Type | Description |
| :-- | :-- | :-- |
| `name` | string | The name of the NAT rule. |
| `resourceGroupName` | string | The name of the resource group the NAT rule was deployed into. |
| `resourceId` | string | The resource ID of the NAT rule. |

## Cross-referenced modules

_None_
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "0.1"
}
Loading