Azure Network Gateway Connection

This page shows how to write Terraform and Azure Resource Manager for Network Gateway Connection and write them securely.

azurerm_vpn_gateway_connection (Terraform)

The Gateway Connection in Network can be configured in Terraform with the resource name azurerm_vpn_gateway_connection. The following sections describe 9 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L79
resource "azurerm_vpn_gateway_connection" "az_vpngw_conn_1" {
    name               = var.vpn_connection_name1
    remote_vpn_site_id = azurerm_vpn_site.az_vpnsite_1.id
    vpn_gateway_id     = azurerm_vpn_gateway.default.id
    vpn_link {
        name = "vpn_conn_1"
azurerm-vpn-gateway.tf#L31
resource "azurerm_vpn_gateway_connection" "homelab1" {
  name               = "homelab1"
  vpn_gateway_id     = azurerm_vpn_gateway.canadacentral.id
  remote_vpn_site_id = azurerm_vpn_site.homelab1.id

  vpn_link {
vnet-gw.tf#L46
resource "azurerm_vpn_gateway_connection" "microhack-vwan-eus2-onprem" {
  name               = "vwan-eus2-onprem"
  vpn_gateway_id     = azurerm_vpn_gateway.microhack-eus2-hub-vng.id
  remote_vpn_site_id = azurerm_vpn_site.microhack-eus2-onprem-site.id
  vpn_link {
    name             = "link1"
module.tf#L11
resource "azurerm_vpn_gateway_connection" "vpn_gateway_connection" {
  name                      = azurecaf_name.vpn_gateway_connection.result
  vpn_gateway_id            = var.vpn_gateway_id
  internet_security_enabled = var.settings.internet_security_enabled

  remote_vpn_site_id = coalesce(
alpha.tf#L27
resource "azurerm_vpn_gateway_connection" "alpha" {
  name               = "alpha-connection"
  vpn_gateway_id     = data.terraform_remote_state.vwan.outputs.vpn_gateway.id
  remote_vpn_site_id = azurerm_vpn_site.alpha.id

  vpn_link {
beta.tf#L27
resource "azurerm_vpn_gateway_connection" "beta" {
  name               = "beta-connection"
  vpn_gateway_id     = data.terraform_remote_state.vwan.outputs.vpn_gateway.id
  remote_vpn_site_id = azurerm_vpn_site.beta.id

  vpn_link {
module.tf#L11
resource "azurerm_vpn_gateway_connection" "vpn_gateway_connection" {
  name                      = azurecaf_name.vpn_gateway_connection.result
  vpn_gateway_id            = var.vpn_gateway_id
  internet_security_enabled = var.settings.internet_security_enabled

  remote_vpn_site_id = coalesce(
module.tf#L11
resource "azurerm_vpn_gateway_connection" "vpn_gateway_connection" {
  name                      = azurecaf_name.vpn_gateway_connection.result
  vpn_gateway_id            = var.vpn_gateway_id
  internet_security_enabled = var.settings.internet_security_enabled

  remote_vpn_site_id = coalesce(
main.tf#L98
resource "azurerm_vpn_gateway_connection" "connections" {
  provider           = azurerm.vwantarget
  for_each           = var.vwanVpnConnections
  name               = each.value["vpnConnName"]
  vpn_gateway_id     = each.value["vpnConnGtwyId"]
  remote_vpn_site_id = each.value["vpnConnRemoteSiteId"]

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a VPN Gateway Connection.

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.

risk-label

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.

risk-label

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.

risk-label

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.

Review your Azure Network settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Network/vpnGateways/vpnConnections (Azure Resource Manager)

The vpnGateways/vpnConnections in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/vpnGateways/vpnConnections. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Parameters

  • name required - string
  • type required - string
  • apiVersion required - string
  • properties required
      • remoteVpnSite optional
          • id required - string

            Resource ID.

      • routingWeight optional - integer

        Routing weight for vpn connection.

      • dpdTimeoutSeconds optional - integer

        DPD timeout in seconds for vpn connection.

      • connectionStatus optional - string

        The connection status.

      • vpnConnectionProtocolType optional - string

        Connection protocol used for this connection.

      • connectionBandwidth optional - integer

        Expected bandwidth in MBPS.

      • sharedKey optional - string

        SharedKey for the vpn connection.

      • enableBgp optional - boolean

        EnableBgp flag.

      • usePolicyBasedTrafficSelectors optional - boolean

        Enable policy-based traffic selectors.

      • ipsecPolicies optional array
          • saLifeTimeSeconds required - integer

            The IPSec Security Association (also called Quick Mode or Phase 2 SA) lifetime in seconds for a site to site VPN tunnel.

          • saDataSizeKilobytes required - integer

            The IPSec Security Association (also called Quick Mode or Phase 2 SA) payload size in KB for a site to site VPN tunnel.

          • ipsecEncryption required - string

            The IPSec encryption algorithm (IKE phase 1).

          • ipsecIntegrity required - string

            The IPSec integrity algorithm (IKE phase 1).

          • ikeEncryption required - string

            The IKE encryption algorithm (IKE phase 2).

          • ikeIntegrity required - string

            The IKE integrity algorithm (IKE phase 2).

          • dhGroup required - string

            The DH Group used in IKE Phase 1 for initial SA.

          • pfsGroup required - string

            The Pfs Group used in IKE Phase 2 for new child SA.

      • trafficSelectorPolicies optional array
          • localAddressRanges required - array

            A collection of local address spaces in CIDR format.

          • remoteAddressRanges required - array

            A collection of remote address spaces in CIDR format.

      • enableRateLimiting optional - boolean

        EnableBgp flag.

      • enableInternetSecurity optional - boolean

        Enable internet security.

      • useLocalAzureIpAddress optional - boolean

        Use local azure ip to initiate connection.

      • vpnLinkConnections optional array
          • properties optional
              • vpnSiteLink optional
                  • id required - string

                    Resource ID.

              • routingWeight optional - integer

                Routing weight for vpn connection.

              • vpnLinkConnectionMode optional - string

                Vpn link connection mode.

              • connectionStatus optional - string

                The connection status.

              • vpnConnectionProtocolType optional - string

                Connection protocol used for this connection.

              • connectionBandwidth optional - integer

                Expected bandwidth in MBPS.

              • sharedKey optional - string

                SharedKey for the vpn connection.

              • enableBgp optional - boolean

                EnableBgp flag.

              • usePolicyBasedTrafficSelectors optional - boolean

                Enable policy-based traffic selectors.

              • ipsecPolicies optional array
                  • saLifeTimeSeconds required - integer

                    The IPSec Security Association (also called Quick Mode or Phase 2 SA) lifetime in seconds for a site to site VPN tunnel.

                  • saDataSizeKilobytes required - integer

                    The IPSec Security Association (also called Quick Mode or Phase 2 SA) payload size in KB for a site to site VPN tunnel.

                  • ipsecEncryption required - string

                    The IPSec encryption algorithm (IKE phase 1).

                  • ipsecIntegrity required - string

                    The IPSec integrity algorithm (IKE phase 1).

                  • ikeEncryption required - string

                    The IKE encryption algorithm (IKE phase 2).

                  • ikeIntegrity required - string

                    The IKE integrity algorithm (IKE phase 2).

                  • dhGroup required - string

                    The DH Group used in IKE Phase 1 for initial SA.

                  • pfsGroup required - string

                    The Pfs Group used in IKE Phase 2 for new child SA.

              • enableRateLimiting optional - boolean

                EnableBgp flag.

              • useLocalAzureIpAddress optional - boolean

                Use local azure ip to initiate connection.

              • ingressNatRules optional array
                  • id required - string

                    Resource ID.

              • egressNatRules optional array
                  • id required - string

                    Resource ID.

          • name optional - string

            The name of the resource that is unique within a resource group. This name can be used to access the resource.

      • routingConfiguration optional
          • associatedRouteTable optional
              • id required - string

                Resource ID.

          • propagatedRouteTables optional
              • labels optional - array

                The list of labels.

              • ids optional array
                  • id required - string

                    Resource ID.

          • vnetRoutes optional
              • staticRoutes optional array
                  • name optional - string

                    The name of the StaticRoute that is unique within a VnetRoute.

                  • addressPrefixes optional - array

                    List of all address prefixes.

                  • nextHopIpAddress optional - string

                    The ip address of the next hop.

Frequently asked questions

What is Azure Network Gateway Connection?

Azure Network Gateway Connection 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 Connection?

For Terraform, the rickchen918/vwan, raykao/hub-spoke-environment and zipphreak/azure-vwan-microhack2.0 source code examples are useful. See the Terraform Example section for further details.