Skip to main content

VPN

This module makes it easy to deploy either GCP-to-GCP or GCP-to-On-prem VPN using Cloud HA VPN including HA VPN Gateway itself. VPN includes one or more VPN instances (connections).

Each created VPN instance is represented by 1..4 VPN tunnels that taget remote VPN gateway(s) located in a single remote location. Remote VPN gateway(s) might have singe IP address (redundancy_type = "SINGLE_IP_INTERNALLY_REDUNDANT") or 2 IP addresses (redundancy_type = "TWO_IPS_REDUNDANCY").

GitHub Logo Terraform Logo

Example

data "google_compute_network" "test" {
name = "<network_name>"
project = "<project_id>"
}

module "vpn" {
source = "../../../modules/vpn"

project = "<project_id>"
region = "us-central1"

vpn_gateway_name = "my-test-gateway"
router_name = "my-test-router"
network = data.google_compute_network.test.self_link

vpn_config = {
router_asn = 65000
local_network = "vpc-vpn"

router_advertise_config = {
ip_ranges = {
"10.10.0.0/16" : "GCP range 1"
}
mode = "CUSTOM"
groups = null
}

instances = {
vpn-to-onprem1 = {
name = "vpn-to-onprem1",
peer_external_gateway = {
redundancy_type = "SINGLE_IP_INTERNALLY_REDUNDANT"
interfaces = [{
id = 0
ip_address = "1.1.1.1"
}]
},
tunnels = {
remote0 = {
bgp_peer = {
address = "169.254.1.2"
asn = 65001
}
bgp_peer_options = null
bgp_session_range = "169.254.1.1/30"
ike_version = 2
vpn_gateway_interface = 0
peer_external_gateway_interface = 0
shared_secret = "secret"
}
remote1 = {
bgp_peer = {
address = "169.254.1.6"
asn = 65001
}
bgp_peer_options = null
bgp_session_range = "169.254.1.5/30"
ike_version = 2
vpn_gateway_interface = 1
peer_external_gateway_interface = null
shared_secret = "secret"
}
}
}
vpn-to-onprem2 = {
name = "vpn-to-onprem2",
peer_external_gateway = {
redundancy_type = "TWO_IPS_REDUNDANCY"
interfaces = [{
id = 0
ip_address = "3.3.3.3"
}, {
id = 1
ip_address = "4.4.4.4"
}]
},
tunnels = {
remote0 = {
bgp_peer = {
address = "169.254.2.2"
asn = 65002
}
bgp_peer_options = null
bgp_session_range = "169.254.2.1/30"
ike_version = 2
vpn_gateway_interface = 0
peer_external_gateway_interface = 0
shared_secret = "secret"
}
remote1 = {
bgp_peer = {
address = "169.254.2.6"
asn = 65002
}
bgp_peer_options = null
bgp_session_range = "169.254.2.5/30"
ike_version = 2
vpn_gateway_interface = 1
peer_external_gateway_interface = 1
shared_secret = "secret"
}
}
}
vpn-to-gcp = {
name = "vpn-to-gcp",

peer_gcp_gateway = "https://www.googleapis.com/compute/v1/projects/<remote_project_id>/regions/<region>/vpnGateways/<remote_vpn_gw_name>"

tunnels = {
remote0 = {
bgp_peer = {
address = "169.254.3.2"
asn = 65003
}
bgp_peer_options = null
bgp_session_range = "169.254.3.1/30"
ike_version = 2
vpn_gateway_interface = 0
peer_external_gateway_interface = null
shared_secret = "secret"
}
remote1 = {
bgp_peer = {
address = "169.254.3.6"
asn = 65003
}
bgp_peer_options = null
bgp_session_range = "169.254.3.5/30"
ike_version = 2
vpn_gateway_interface = 1
peer_external_gateway_interface = 1
shared_secret = "secret"
}
}
}
}
}
}

Reference

Requirements

NameVersion
terraform>= 1.3, < 2.0
google>= 4.58

Providers

NameVersion
google>= 4.58
google-betan/a
randomn/a

Modules

No modules.

Resources

NameType
google-beta_google_compute_vpn_tunnel.tunnelsresource
google_compute_external_vpn_gateway.external_gatewayresource
google_compute_ha_vpn_gateway.ha_gatewayresource
google_compute_router.routerresource
google_compute_router_interface.router_interfaceresource
google_compute_router_peer.bgp_peerresource
random_id.secretresource

Inputs

NameDescriptionTypeDefaultRequired
labelsLabels for VPN componentsmap(string){}no
networkVPC network ID that should be used for deploymentstringn/ayes
projectn/astringnullno
regionRegion to deploy VPN gateway instringn/ayes
router_nameCloud router name. The router is created by the modulestringnullno
vpn_configVPN configuration from GCP to on-prem or from GCP to GCP.
If you'd like secrets to be randomly generated set shared_secret to empty string ("").

Example:vpn_config = {
router_asn = 65000
local_network = "vpc-vpn"

router_advertise_config = {
ip_ranges = {
"10.10.0.0/16" : "GCP range 1"
}
mode = "CUSTOM"
groups = null
}

instances = {
vpn-to-onprem = {
name = "vpn-to-onprem",
peer_external_gateway = {
redundancy_type = "TWO_IPS_REDUNDANCY"
interfaces = [{
id = 0
ip_address = "1.1.1.1"
}, {
id = 1
ip_address = "2.2.2.2"
}]
},
tunnels = {
remote0 = {
bgp_peer = {
address = "169.254.1.2"
asn = 65001
}
bgp_peer_options = null
bgp_session_range = "169.254.1.1/30"
ike_version = 2
vpn_gateway_interface = 0
peer_external_gateway_interface = 0
shared_secret = "secret"
}
remote1 = {
bgp_peer = {
address = "169.254.1.6"
asn = 65001
}
bgp_peer_options = null
bgp_session_range = "169.254.1.5/30"
ike_version = 2
vpn_gateway_interface = 1
peer_external_gateway_interface = 1
shared_secret = "secret"
}
}
}
}
}
anyn/ayes
vpn_gateway_nameVPN gateway name. Gateway created by the modulestringn/ayes

Outputs

NameDescription
random_secretHA VPN IPsec tunnels secret that has been randomly generated
vpn_gw_local_address_1HA VPN gateway IP address 1
vpn_gw_local_address_2HA VPN gateway IP address 2
vpn_gw_nameHA VPN gateway name
vpn_gw_self_linkHA VPN gateway self_link

Requirements

NameVersion
terraform>= 1.2, < 2.0
google== 4.58

Providers

NameVersion
google== 4.58

Modules

NameSourceVersion
vpn_haterraform-google-modules/vpn/google3.0.1

Resources

NameType
google_compute_ha_vpn_gateway.ha_gatewayresource

Inputs

NameDescriptionTypeDefaultRequired
projectn/astringnullno
regionRegion to deploy VPN gateway instringn/ayes
vpc_network_idVPC network ID that should be used for deploymentstringn/ayes
vpnVPN configuration from GCP to on-prem or from GCP to GCP.
If you'd like secrets to be randomly generated set shared_secret to empty string ("").

Example:vpn = {
router_asn = 65000
local_network = "vpc-vpn"

router_advertise_config = {
ip_ranges = {
"10.10.0.0/16" : "GCP range 1"
}
mode = "CUSTOM"
groups = null
}

instances = {
vpn-to-onprem = {
name = "vpn-to-onprem",
peer_external_gateway = {
redundancy_type = "TWO_IPS_REDUNDANCY"
interfaces = [{
id = 0
ip_address = "1.1.1.1"
}, {
id = 1
ip_address = "2.2.2.2"
}]
},
tunnels = {
remote0 = {
bgp_peer = {
address = "169.254.1.2"
asn = 65001
}
bgp_peer_options = null
bgp_session_range = "169.254.1.1/30"
ike_version = 2
vpn_gateway_interface = 0
peer_external_gateway_interface = 0
shared_secret = "secret"
}
remote1 = {
bgp_peer = {
address = "169.254.1.6"
asn = 65001
}
bgp_peer_options = null
bgp_session_range = "169.254.1.5/30"
ike_version = 2
vpn_gateway_interface = 1
peer_external_gateway_interface = 1
shared_secret = "secret"
}
}
}
}
anyn/ayes
vpn_gateway_nameVPN gateway namestringn/ayes

Outputs

NameDescription
local_ipsec_gw2_address_2HA VPN gateway IP address 2
local_ipsec_gw_address_1HA VPN gateway IP address 1
random_secrets_mapHA VPN IPsec tunnels secrets that were randomly generated
vpn_gateway_nameHA VPN gateway name
vpn_gateway_self_linkHA VPN gateway self_link