160 lines
7.1 KiB
Markdown
160 lines
7.1 KiB
Markdown
# Cloud HA VPN Module
|
|
|
|
This module makes it easy to deploy either GCP-to-GCP or GCP-to-On-prem [Cloud HA VPN](https://cloud.google.com/vpn/docs/concepts/overview#ha-vpn).
|
|
|
|
## Examples
|
|
|
|
### GCP to GCP
|
|
|
|
```hcl
|
|
module "vpn-1" {
|
|
source = "./fabric/modules/net-vpn-ha"
|
|
project_id = var.project_id
|
|
region = "europe-west4"
|
|
network = var.vpc1.self_link
|
|
name = "net1-to-net-2"
|
|
peer_gateways = {
|
|
default = { gcp = module.vpn-2.self_link }
|
|
}
|
|
router_config = {
|
|
asn = 64514
|
|
custom_advertise = {
|
|
all_subnets = true
|
|
ip_ranges = {
|
|
"10.0.0.0/8" = "default"
|
|
}
|
|
}
|
|
}
|
|
tunnels = {
|
|
remote-0 = {
|
|
bgp_peer = {
|
|
address = "169.254.1.1"
|
|
asn = 64513
|
|
}
|
|
bgp_session_range = "169.254.1.2/30"
|
|
vpn_gateway_interface = 0
|
|
}
|
|
remote-1 = {
|
|
bgp_peer = {
|
|
address = "169.254.2.1"
|
|
asn = 64513
|
|
}
|
|
bgp_session_range = "169.254.2.2/30"
|
|
vpn_gateway_interface = 1
|
|
}
|
|
}
|
|
}
|
|
|
|
module "vpn-2" {
|
|
source = "./fabric/modules/net-vpn-ha"
|
|
project_id = var.project_id
|
|
region = "europe-west4"
|
|
network = var.vpc2.self_link
|
|
name = "net2-to-net1"
|
|
router_config = { asn = 64513 }
|
|
peer_gateways = {
|
|
default = { gcp = module.vpn-1.self_link }
|
|
}
|
|
tunnels = {
|
|
remote-0 = {
|
|
bgp_peer = {
|
|
address = "169.254.1.2"
|
|
asn = 64514
|
|
}
|
|
bgp_session_range = "169.254.1.1/30"
|
|
shared_secret = module.vpn-1.random_secret
|
|
vpn_gateway_interface = 0
|
|
}
|
|
remote-1 = {
|
|
bgp_peer = {
|
|
address = "169.254.2.2"
|
|
asn = 64514
|
|
}
|
|
bgp_session_range = "169.254.2.1/30"
|
|
shared_secret = module.vpn-1.random_secret
|
|
vpn_gateway_interface = 1
|
|
}
|
|
}
|
|
}
|
|
# tftest modules=2 resources=18
|
|
```
|
|
|
|
Note: When using the `for_each` meta-argument you might experience a Cycle Error due to the multiple `net-vpn-ha` modules referencing each other. To fix this you can create the [google_compute_ha_vpn_gateway](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_ha_vpn_gateway) resources separately and reference them in the `net-vpn-ha` module via the `vpn_gateway` and `peer_gcp_gateway` variables.
|
|
|
|
### GCP to on-prem
|
|
|
|
```hcl
|
|
module "vpn_ha" {
|
|
source = "./fabric/modules/net-vpn-ha"
|
|
project_id = var.project_id
|
|
region = var.region
|
|
network = var.vpc.self_link
|
|
name = "mynet-to-onprem"
|
|
peer_gateways = {
|
|
default = {
|
|
external = {
|
|
redundancy_type = "SINGLE_IP_INTERNALLY_REDUNDANT"
|
|
interfaces = ["8.8.8.8"] # on-prem router ip address
|
|
}
|
|
}
|
|
}
|
|
router_config = { asn = 64514 }
|
|
tunnels = {
|
|
remote-0 = {
|
|
bgp_peer = {
|
|
address = "169.254.1.1"
|
|
asn = 64513
|
|
}
|
|
bgp_session_range = "169.254.1.2/30"
|
|
peer_external_gateway_interface = 0
|
|
shared_secret = "mySecret"
|
|
vpn_gateway_interface = 0
|
|
}
|
|
remote-1 = {
|
|
bgp_peer = {
|
|
address = "169.254.2.1"
|
|
asn = 64513
|
|
}
|
|
bgp_session_range = "169.254.2.2/30"
|
|
peer_external_gateway_interface = 0
|
|
shared_secret = "mySecret"
|
|
vpn_gateway_interface = 1
|
|
}
|
|
}
|
|
}
|
|
# tftest modules=1 resources=10
|
|
```
|
|
<!-- BEGIN TFDOC -->
|
|
|
|
## Variables
|
|
|
|
| name | description | type | required | default |
|
|
|---|---|:---:|:---:|:---:|
|
|
| [name](variables.tf#L17) | VPN Gateway name (if an existing VPN Gateway is not used), and prefix used for dependent resources. | <code>string</code> | ✓ | |
|
|
| [network](variables.tf#L22) | VPC used for the gateway and routes. | <code>string</code> | ✓ | |
|
|
| [project_id](variables.tf#L46) | Project where resources will be created. | <code>string</code> | ✓ | |
|
|
| [region](variables.tf#L51) | Region used for resources. | <code>string</code> | ✓ | |
|
|
| [router_config](variables.tf#L56) | Cloud Router configuration for the VPN. If you want to reuse an existing router, set create to false and use name to specify the desired router. | <code title="object({ create = optional(bool, true) asn = number name = optional(string) keepalive = optional(number) custom_advertise = optional(object({ all_subnets = bool ip_ranges = map(string) })) })">object({…})</code> | ✓ | |
|
|
| [peer_gateways](variables.tf#L27) | Configuration of the (external or GCP) peer gateway. | <code title="map(object({ external = optional(object({ redundancy_type = string interfaces = list(string) })) gcp = optional(string) }))">map(object({…}))</code> | | <code>{}</code> |
|
|
| [tunnels](variables.tf#L71) | VPN tunnel configurations. | <code title="map(object({ bgp_peer = object({ address = string asn = number route_priority = optional(number, 1000) custom_advertise = optional(object({ all_subnets = bool all_vpc_subnets = bool all_peer_vpc_subnets = bool ip_ranges = map(string) })) }) bgp_session_range = string ike_version = optional(number, 2) peer_external_gateway_interface = optional(number) peer_gateway = optional(string, "default") router = optional(string) shared_secret = optional(string) vpn_gateway_interface = number }))">map(object({…}))</code> | | <code>{}</code> |
|
|
| [vpn_gateway](variables.tf#L99) | HA VPN Gateway Self Link for using an existing HA VPN Gateway. Ignored if `vpn_gateway_create` is set to `true`. | <code>string</code> | | <code>null</code> |
|
|
| [vpn_gateway_create](variables.tf#L105) | Create HA VPN Gateway. | <code>bool</code> | | <code>true</code> |
|
|
|
|
## Outputs
|
|
|
|
| name | description | sensitive |
|
|
|---|---|:---:|
|
|
| [bgp_peers](outputs.tf#L18) | BGP peer resources. | |
|
|
| [external_gateway](outputs.tf#L25) | External VPN gateway resource. | |
|
|
| [gateway](outputs.tf#L30) | VPN gateway resource (only if auto-created). | |
|
|
| [name](outputs.tf#L35) | VPN gateway name (only if auto-created). . | |
|
|
| [random_secret](outputs.tf#L40) | Generated secret. | |
|
|
| [router](outputs.tf#L45) | Router resource (only if auto-created). | |
|
|
| [router_name](outputs.tf#L50) | Router name. | |
|
|
| [self_link](outputs.tf#L55) | HA VPN gateway self link. | |
|
|
| [tunnel_names](outputs.tf#L60) | VPN tunnel names. | |
|
|
| [tunnel_self_links](outputs.tf#L68) | VPN tunnel self links. | |
|
|
| [tunnels](outputs.tf#L76) | VPN tunnel resources. | |
|
|
|
|
<!-- END TFDOC -->
|