» google_compute_ha_vpn_gateway

Represents a VPN gateway running in GCP. This virtual device is managed by Google, but used only by you. This type of VPN Gateway allows for the creation of VPN solutions with higher availability than classic Target VPN Gateways.

To get more information about HaVpnGateway, see:

» Example Usage - Ha Vpn Gateway Basic

resource "google_compute_ha_vpn_gateway" "ha_gateway1" {
  provider = "google-beta"
  region   = "us-central1"
  name     = "ha-vpn-1"
  network  = "${google_compute_network.network1.self_link}"
}

resource "google_compute_network" "network1" {
  provider                = "google-beta"
  name                    = "network1"
  auto_create_subnetworks = false
}

» Example Usage - Ha Vpn Gateway Gcp To Gcp

resource "google_compute_ha_vpn_gateway" "ha_gateway1" {
  provider = "google-beta"
  region   = "us-central1"
  name     = "ha-vpn-1"
  network  = "${google_compute_network.network1.self_link}"
}

resource "google_compute_ha_vpn_gateway" "ha_gateway2" {
  provider = "google-beta"
  region   = "us-central1"
  name     = "ha-vpn-2"
  network  = "${google_compute_network.network2.self_link}"
}

resource "google_compute_network" "network1" {
  provider                = "google-beta"
  name                    = "network1"
  routing_mode            = "GLOBAL"
  auto_create_subnetworks = false
}

resource "google_compute_network" "network2" {
  provider                = "google-beta"
  name                    = "network2"
  routing_mode            = "GLOBAL"
  auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "network1_subnet1" {
  provider = "google-beta"
  name          = "ha-vpn-subnet-1"
  ip_cidr_range = "10.0.1.0/24"
  region        = "us-central1"
  network       = "${google_compute_network.network1.self_link}"
}

resource "google_compute_subnetwork" "network1_subnet2" {
  provider = "google-beta"
  name          = "ha-vpn-subnet-2"
  ip_cidr_range = "10.0.2.0/24"
  region        = "us-west1"
  network       = "${google_compute_network.network1.self_link}"
}

resource "google_compute_subnetwork" "network2_subnet1" {
  provider = "google-beta"
  name          = "ha-vpn-subnet-3"
  ip_cidr_range = "192.168.1.0/24"
  region        = "us-central1"
  network       = "${google_compute_network.network2.self_link}"
}

resource "google_compute_subnetwork" "network2_subnet2" {
  provider = "google-beta"
  name          = "ha-vpn-subnet-4"
  ip_cidr_range = "192.168.2.0/24"
  region        = "us-east1"
  network       = "${google_compute_network.network2.self_link}"
}

resource "google_compute_router" "router1" {
  provider = "google-beta"
  name    = "ha-vpn-router1"
  network = "${google_compute_network.network1.name}"
  bgp {
    asn = 64514
  }
}

resource "google_compute_router" "router2" {
  provider = "google-beta"
  name     = "ha-vpn-router2"
  network  = "${google_compute_network.network2.name}"
  bgp {
    asn = 64515
  }
}

resource "google_compute_vpn_tunnel" "tunnel1" {
  provider         = "google-beta"
  name             = "ha-vpn-tunnel1"
  region           = "us-central1"
  vpn_gateway      = "${google_compute_ha_vpn_gateway.ha_gateway1.self_link}"
  peer_gcp_gateway = "${google_compute_ha_vpn_gateway.ha_gateway2.self_link}"
  shared_secret    = "a secret message"
  router           = "${google_compute_router.router1.self_link}"
  vpn_gateway_interface = 0
}

resource "google_compute_vpn_tunnel" "tunnel2" {
  provider         = "google-beta"
  name             = "ha-vpn-tunnel2"
  region           = "us-central1"
  vpn_gateway      = "${google_compute_ha_vpn_gateway.ha_gateway1.self_link}"
  peer_gcp_gateway = "${google_compute_ha_vpn_gateway.ha_gateway2.self_link}"
  shared_secret    = "a secret message"
  router           = " ${google_compute_router.router1.self_link}"
  vpn_gateway_interface = 1
}

resource "google_compute_vpn_tunnel" "tunnel3" {
  provider         = "google-beta"
  name             = "ha-vpn-tunnel3"
  region           = "us-central1"
  vpn_gateway      = "${google_compute_ha_vpn_gateway.ha_gateway2.self_link}"
  peer_gcp_gateway = "${google_compute_ha_vpn_gateway.ha_gateway1.self_link}"
  shared_secret    = "a secret message"
  router           = "${google_compute_router.router2.self_link}"
  vpn_gateway_interface = 0
}

resource "google_compute_vpn_tunnel" "tunnel4" {
  provider         = "google-beta"
  name             = "ha-vpn-tunnel4"
  region           = "us-central1"
  vpn_gateway      = "${google_compute_ha_vpn_gateway.ha_gateway2.self_link}"
  peer_gcp_gateway = "${google_compute_ha_vpn_gateway.ha_gateway1.self_link}"
  shared_secret    = "a secret message"
  router           = "${google_compute_router.router2.self_link}"
  vpn_gateway_interface = 1
}

resource "google_compute_router_interface" "router1_interface1" {
  provider = "google-beta"
  name       = "router1-interface1"
  router     = "${google_compute_router.router1.name}"
  region     = "us-central1"
  ip_range   = "169.254.0.1/30"
  vpn_tunnel = "${google_compute_vpn_tunnel.tunnel1.name}"
}

resource "google_compute_router_peer" "router1_peer1" {
  provider = "google-beta"
  name                      = "router1-peer1"
  router                    = "${google_compute_router.router1.name}"
  region                    = "us-central1"
  peer_ip_address           = "169.254.0.2"
  peer_asn                  = 64515
  advertised_route_priority = 100
  interface                 = "${google_compute_router_interface.router1_interface1.name}"
}

resource "google_compute_router_interface" "router1_interface2" {
  provider = "google-beta"
  name       = "router1-interface2"
  router     = "${google_compute_router.router1.name}"
  region     = "us-central1"
  ip_range   = "169.254.1.1/30"
  vpn_tunnel = "${google_compute_vpn_tunnel.tunnel2.name}"
}

resource "google_compute_router_peer" "router1_peer2" {
  provider = "google-beta"
  name                      = "router1-peer2"
  router                    = "${google_compute_router.router1.name}"
  region                    = "us-central1"
  peer_ip_address           = "169.254.1.2"
  peer_asn                  = 64515
  advertised_route_priority = 100
  interface                 = "${google_compute_router_interface.router1_interface2.name}"
}

resource "google_compute_router_interface" "router2_interface1" {
  provider = "google-beta"
  name       = "router2-interface1"
  router     = "${google_compute_router.router2.name}"
  region     = "us-central1"
  ip_range   = "169.254.0.1/30"
  vpn_tunnel = "${google_compute_vpn_tunnel.tunnel3.name}"
}

resource "google_compute_router_peer" "router2_peer1" {
  provider                  = "google-beta"
  name                      = "router2-peer1"
  router                    = "${google_compute_router.router2.name}"
  region                    = "us-central1"
  peer_ip_address           = "169.254.0.2"
  peer_asn                  = 64514
  advertised_route_priority = 100
  interface                 = "${google_compute_router_interface.router2_interface1.name}"
}

resource "google_compute_router_interface" "router2_interface2" {
  provider = "google-beta"
  name       = "router2-interface2"
  router     = "${google_compute_router.router2.name}"
  region     = "us-central1"
  ip_range   = "169.254.1.1/30"
  vpn_tunnel = "${google_compute_vpn_tunnel.tunnel4.name}"
}

resource "google_compute_router_peer" "router2_peer2" {
  provider                  = "google-beta"
  name                      = "router2-peer2"
  router                    = "${google_compute_router.router2.name}"
  region                    = "us-central1"
  peer_ip_address           = "169.254.1.2"
  peer_asn                  = 64514
  advertised_route_priority = 100
  interface                 = "${google_compute_router_interface.router2_interface2.name}"
}

» Argument Reference

The following arguments are supported:

  • name - (Required) Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

  • network - (Required) The network this VPN gateway is accepting traffic for.


  • description - (Optional) An optional description of this resource.

  • region - (Optional) The region this gateway should sit in.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

» Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • vpn_interfaces - A list of interfaces on this VPN gateway. Structure is documented below.
  • self_link - The URI of the created resource.

The vpn_interfaces block contains:

  • id - (Optional) The numeric ID of this VPN gateway interface.

  • ip_address - (Optional) The external IP address for this VPN gateway interface.

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 4 minutes.
  • delete - Default is 4 minutes.

» Import

HaVpnGateway can be imported using any of these accepted formats:

$ terraform import -provider=google-beta google_compute_ha_vpn_gateway.default projects/{{project}}/regions/{{region}}/vpnGateways/{{name}}
$ terraform import -provider=google-beta google_compute_ha_vpn_gateway.default {{project}}/{{region}}/{{name}}
$ terraform import -provider=google-beta google_compute_ha_vpn_gateway.default {{region}}/{{name}}
$ terraform import -provider=google-beta google_compute_ha_vpn_gateway.default {{name}}

» User Project Overrides

This resource supports User Project Overrides.