Azure Network Gateway
This page shows how to write Terraform and Azure Resource Manager for Network Gateway and write them securely.
azurerm_virtual_network_gateway (Terraform)
The Gateway in Network can be configured in Terraform with the resource name azurerm_virtual_network_gateway. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_virtual_network_gateway" "hubvpn" {
name = "hubvpn"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
type = "Vpn"
resource "azurerm_virtual_network_gateway" "gw-rg1" {
name = "gw-rg1"
location = azurerm_resource_group.rg1.location
resource_group_name = azurerm_resource_group.rg1.name
type = "Vpn"
resource "azurerm_virtual_network_gateway" "hubvpngw" {
name = "hubvpngw"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
type = "Vpn"
resource "azurerm_virtual_network_gateway" "hubvpngw" {
name = "hubvpngw"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
type = "Vpn"
resource "azurerm_virtual_network_gateway" "Basic" {
name = "test"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
type = "Vpn"
resource "azurerm_virtual_network_gateway" "hubvpngw" {
name = var.vpngwname
location = var.location
resource_group_name = var.resource_group_name
tags = var.tags
resource "azurerm_virtual_network_gateway" "vpn-hub" {
name = "hod-ukw-prod-testinfra-vng-hub"
resource_group_name = azurerm_resource_group.rsg-hub.name
location = var.location
type = "Vpn"
resource "azurerm_virtual_network_gateway" "vng" {
name = "vpn-gateway"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
type = "Vpn"
resource "azurerm_virtual_network_gateway" "hub-vnet-gateway" {
name = "hub-vpn-gateway1"
location = azurerm_resource_group.hub-rg.location
resource_group_name = azurerm_resource_group.hub-rg.name
type = "Vpn"
resource "azurerm_virtual_network_gateway" "onprem_vpn_gateway" {
name = "onprem-vpn-gateway"
location = var.onprem_location
resource_group_name = var.onprem_rg_name
type = "Vpn"
Parameters
-
active_activeoptional computed - bool -
default_local_network_gateway_idoptional - string -
enable_bgpoptional computed - bool -
generationoptional computed - string -
idoptional computed - string -
locationrequired - string -
namerequired - string -
private_ip_address_enabledoptional - bool -
resource_group_namerequired - string -
skurequired - string -
tagsoptional - map from string to string -
typerequired - string -
vpn_typeoptional - string -
bgp_settingslist block-
asnoptional - number -
peer_weightoptional - number -
peering_addressoptional computed - string -
peering_addresseslist block-
apipa_addressesoptional - list of string -
default_addressesoptional computed - list of string -
ip_configuration_nameoptional computed - string -
tunnel_ip_addressesoptional computed - list of string
-
-
-
custom_routelist block-
address_prefixesoptional - set of string
-
-
ip_configurationlist block-
nameoptional - string -
private_ip_address_allocationoptional - string -
public_ip_address_idrequired - string -
subnet_idrequired - string
-
-
timeoutssingle block -
vpn_client_configurationlist block-
aad_audienceoptional - string -
aad_issueroptional - string -
aad_tenantoptional - string -
address_spacerequired - list of string -
radius_server_addressoptional - string -
radius_server_secretoptional - string -
vpn_client_protocolsoptional computed - set of string -
revoked_certificateset block-
namerequired - string -
thumbprintrequired - string
-
-
root_certificateset block-
namerequired - string -
public_cert_datarequired - string
-
-
Explanation in Terraform Registry
Manages a Virtual Network Gateway to establish secure, cross-premises connectivity. -> Note: Please be aware that provisioning a Virtual Network Gateway takes a long time (between 30 minutes and 1 hour)
Tips: Best Practices for The Other Azure Network Resources
In addition to the azurerm_network_security_group, Azure Network has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_network_security_group
Ensure to disable RDP port from the Internet
It is better to disable the RDP port from the Internet. RDP access should not be accepted from the Internet (*, 0.0.0.0, /0, internet, any), and consider using the Azure Bastion Service.
azurerm_network_security_rule
Ensure to set a more restrictive CIDR range for ingress from the internet
It is better to set a more restrictive CIDR range not to use very broad subnets. If possible, segments should be divided into smaller subnets.
azurerm_network_watcher_flow_log
Ensure to enable Retention policy for flow logs and set it to enough duration
It is better to enable a retention policy for flow logs. Flow logs show us all network activity in the cloud environment and support us when we face critical incidents.
Microsoft.Network/virtualNetworkGateways (Azure Resource Manager)
The virtualNetworkGateways in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/virtualNetworkGateways. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Network/virtualNetworkGateways",
"name": "branch-ne-vpn",
"location": "northeurope",
"properties": {
"ipConfigurations": [
{
"type": "Microsoft.Network/virtualNetworkGateways",
"location": "eastus2",
"tags": {},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "04ead348-262e-428e-b259-bb37681c027a",
"type": "Microsoft.Network/virtualNetworkGateways"
}
]
"type": "Microsoft.Network/virtualNetworkGateways"
}
]
"type": "Microsoft.Network/virtualNetworkGateways",
"apiVersion": "2019-09-01",
"name": "[variables('vnet1VpnGwName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('vnet1VpnGwIpName'))]",
"type": "Microsoft.Network/virtualNetworkGateways",
"apiVersion": "2020-05-01",
"name": "[parameters('hubVng01Name')]",
"location": "[parameters('location')]",
"tags": {
"Owner": "Block Solutions",
"type": "Microsoft.Network/virtualNetworkGateways",
"name": "[parameters('gatewayName1')]",
"location": "[parameters('location1')]",
"properties": {
"ipConfigurations": [
{
"equals": "Microsoft.Network/virtualNetworkGateways"
},
"then": {
"effect": "deployIfNotExists",
"details": {
"type": "Microsoft.Insights/diagnosticSettings",
"type": "Microsoft.Network/virtualNetworkGateways",
"name": "[parameters('VpnGatewayWestUsName')]",
"apiVersion": "2017-10-01",
"location": "westus",
"scale": null,
"properties": {
"type": "Microsoft.Network/virtualNetworkGateways",
"location": "loc1",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "00000000-0000-0000-0000-000000000000",
"ipConfigurations": [
Parameters
namerequired - stringtyperequired - stringapiVersionrequired - stringlocationrequired - stringResource location.
tagsoptional - stringResource tags.
propertiesrequiredipConfigurationsoptional arraypropertiesoptionalprivateIPAllocationMethodoptional - stringThe private IP address allocation method.
subnetoptionalidrequired - stringResource ID.
publicIPAddressoptionalidrequired - stringResource ID.
nameoptional - stringThe name of the resource that is unique within a resource group. This name can be used to access the resource.
gatewayTypeoptional - stringThe type of this virtual network gateway.
vpnTypeoptional - stringThe type of this virtual network gateway.
vpnGatewayGenerationoptional - stringThe generation for this VirtualNetworkGateway. Must be None if gatewayType is not VPN.
enableBgpoptional - booleanWhether BGP is enabled for this virtual network gateway or not.
enablePrivateIpAddressoptional - booleanWhether private IP needs to be enabled on this gateway for connections or not.
activeActiveoptional - booleanActiveActive flag.
gatewayDefaultSiteoptionalidrequired - stringResource ID.
skuoptionalnameoptional - stringGateway SKU name.
tieroptional - stringGateway SKU tier.
vpnClientConfigurationoptionalvpnClientAddressPooloptionaladdressPrefixesrequired - arrayA list of address blocks reserved for this virtual network in CIDR notation.
vpnClientRootCertificatesoptional arraypropertiesrequiredpublicCertDatarequired - stringThe certificate public data.
nameoptional - stringThe name of the resource that is unique within a resource group. This name can be used to access the resource.
vpnClientRevokedCertificatesoptional arraypropertiesoptionalthumbprintoptional - stringThe revoked VPN client certificate thumbprint.
nameoptional - stringThe name of the resource that is unique within a resource group. This name can be used to access the resource.
vpnClientProtocolsoptional - arrayVpnClientProtocols for Virtual network gateway.
vpnAuthenticationTypesoptional - arrayVPN authentication types for the virtual network gateway..
vpnClientIpsecPoliciesoptional arraysaLifeTimeSecondsrequired - integerThe IPSec Security Association (also called Quick Mode or Phase 2 SA) lifetime in seconds for a site to site VPN tunnel.
saDataSizeKilobytesrequired - integerThe IPSec Security Association (also called Quick Mode or Phase 2 SA) payload size in KB for a site to site VPN tunnel.
ipsecEncryptionrequired - stringThe IPSec encryption algorithm (IKE phase 1).
ipsecIntegrityrequired - stringThe IPSec integrity algorithm (IKE phase 1).
ikeEncryptionrequired - stringThe IKE encryption algorithm (IKE phase 2).
ikeIntegrityrequired - stringThe IKE integrity algorithm (IKE phase 2).
dhGrouprequired - stringThe DH Group used in IKE Phase 1 for initial SA.
pfsGrouprequired - stringThe Pfs Group used in IKE Phase 2 for new child SA.
radiusServerAddressoptional - stringThe radius server address property of the VirtualNetworkGateway resource for vpn client connection.
radiusServerSecretoptional - stringThe radius secret property of the VirtualNetworkGateway resource for vpn client connection.
radiusServersoptional arrayradiusServerAddressrequired - stringThe address of this radius server.
radiusServerScoreoptional - integerThe initial score assigned to this radius server.
radiusServerSecretoptional - stringThe secret used for this radius server.
aadTenantoptional - stringThe AADTenant property of the VirtualNetworkGateway resource for vpn client connection used for AAD authentication.
aadAudienceoptional - stringThe AADAudience property of the VirtualNetworkGateway resource for vpn client connection used for AAD authentication.
aadIssueroptional - stringThe AADIssuer property of the VirtualNetworkGateway resource for vpn client connection used for AAD authentication.
bgpSettingsoptionalasnoptional - integerThe BGP speaker's ASN.
bgpPeeringAddressoptional - stringThe BGP peering address and BGP identifier of this BGP speaker.
peerWeightoptional - integerThe weight added to routes learned from this BGP speaker.
bgpPeeringAddressesoptional arrayipconfigurationIdoptional - stringThe ID of IP configuration which belongs to gateway.
customBgpIpAddressesoptional - arrayThe list of custom BGP peering addresses which belong to IP configuration.
customRoutesoptionaladdressPrefixesrequired - arrayA list of address blocks reserved for this virtual network in CIDR notation.
enableDnsForwardingoptional - booleanWhether dns forwarding is enabled or not.
vNetExtendedLocationResourceIdoptional - stringMAS FIJI customer vnet resource id. VirtualNetworkGateway of type local gateway is associated with the customer vnet.
virtualNetworkExtendedLocationoptionalnamerequired - stringThe name of the extended location.
typerequired - stringThe type of the extended location.
Frequently asked questions
What is Azure Network Gateway?
Azure Network Gateway is a resource for Network of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Network Gateway?
For Terraform, the larryclaman/vpnscaffolds, BBE75/Terraform and rodrigoffonseca/Azure-Network-Terraform-lab source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the tkubica12/azure-virtual-wan, ringend/azure and blinkops/blink-azure-query source code examples are useful. See the Azure Resource Manager Example section for further details.