From 442b40dea068f1f9fe649ab5067df75a223cdd3e Mon Sep 17 00:00:00 2001 From: Awais Malik Date: Wed, 12 Jul 2023 10:58:59 -0700 Subject: [PATCH] feat: adds variables required for FS (#106) --- modules/vpn_ha/README.md | 5 +++-- modules/vpn_ha/main.tf | 9 +++++---- modules/vpn_ha/variables.tf | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/vpn_ha/README.md b/modules/vpn_ha/README.md index bf08d35..7b22ce7 100644 --- a/modules/vpn_ha/README.md +++ b/modules/vpn_ha/README.md @@ -132,10 +132,11 @@ module "vpn_ha" { | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | create\_vpn\_gateway | create a VPN gateway | `bool` | `true` | no | +| keepalive\_interval | The interval in seconds between BGP keepalive messages that are sent to the peer. | `number` | `20` | no | | labels | Labels for vpn components | `map(string)` | `{}` | no | | name | VPN gateway name, and prefix used for dependent resources. | `string` | n/a | yes | | network | VPC used for the gateway and routes. | `string` | n/a | yes | -| peer\_external\_gateway | Configuration of an external VPN gateway to which this VPN is connected. |
object({
redundancy_type = string
interfaces = list(object({
id = number
ip_address = string
}))
})
| `null` | no | +| peer\_external\_gateway | Configuration of an external VPN gateway to which this VPN is connected. |
object({
name = optional(string)
redundancy_type = string
interfaces = list(object({
id = number
ip_address = string
}))
})
| `null` | no | | peer\_gcp\_gateway | Self Link URL of the peer side HA GCP VPN gateway to which this VPN tunnel is connected. | `string` | `null` | no | | project\_id | Project where resources will be created. | `string` | n/a | yes | | region | Region used for resources. | `string` | n/a | yes | @@ -143,7 +144,7 @@ module "vpn_ha" { | router\_advertise\_config | Router custom advertisement configuration, ip\_ranges is a map of address ranges and descriptions. |
object({
groups = list(string)
ip_ranges = map(string)
mode = string
})
| `null` | no | | router\_asn | Router ASN used for auto-created router. | `number` | `64514` | no | | router\_name | Name of router, leave blank to create one. | `string` | `""` | no | -| tunnels | VPN tunnel configurations, bgp\_peer\_options is usually null. |
map(object({
bgp_peer = object({
address = string
asn = number
})
bgp_peer_options = object({
ip_address = string
advertise_groups = list(string)
advertise_ip_ranges = map(string)
advertise_mode = string
route_priority = number
})
bgp_session_range = string
ike_version = number
vpn_gateway_interface = number
peer_external_gateway_interface = number
shared_secret = string
}))
| `{}` | no | +| tunnels | VPN tunnel configurations, bgp\_peer\_options is usually null. |
map(object({
bgp_peer = object({
address = string
asn = number
})
bgp_session_name = optional(string)
bgp_peer_options = object({
ip_address = string
advertise_groups = list(string)
advertise_ip_ranges = map(string)
advertise_mode = string
route_priority = number
})
bgp_session_range = string
ike_version = number
vpn_gateway_interface = number
peer_external_gateway_interface = number
shared_secret = string
}))
| `{}` | no | | vpn\_gateway\_self\_link | self\_link of existing VPN gateway to be used for the vpn tunnel | `string` | `null` | no | ## Outputs diff --git a/modules/vpn_ha/main.tf b/modules/vpn_ha/main.tf index da1d317..4194f2a 100644 --- a/modules/vpn_ha/main.tf +++ b/modules/vpn_ha/main.tf @@ -47,7 +47,7 @@ resource "google_compute_ha_vpn_gateway" "ha_gateway" { resource "google_compute_external_vpn_gateway" "external_gateway" { provider = google-beta count = var.peer_external_gateway != null ? 1 : 0 - name = "external-${var.name}" + name = var.peer_external_gateway.name != null ? var.peer_external_gateway.name : "external-${var.name}" project = var.project_id redundancy_type = var.peer_external_gateway.redundancy_type description = "Terraform managed external VPN gateway" @@ -94,7 +94,8 @@ resource "google_compute_router" "router" { description = range.value } } - asn = var.router_asn + asn = var.router_asn + keepalive_interval = var.keepalive_interval } } @@ -102,7 +103,7 @@ resource "google_compute_router_peer" "bgp_peer" { for_each = var.tunnels region = var.region project = var.project_id - name = "${var.name}-${each.key}" + name = each.value.bgp_session_name != null ? each.value.bgp_session_name : "${var.name}-${each.key}" router = local.router peer_ip_address = each.value.bgp_peer.address peer_asn = each.value.bgp_peer.asn @@ -146,7 +147,7 @@ resource "google_compute_router_interface" "router_interface" { for_each = var.tunnels project = var.project_id region = var.region - name = "${var.name}-${each.key}" + name = each.value.bgp_session_name != null ? each.value.bgp_session_name : "${var.name}-${each.key}" router = local.router ip_range = each.value.bgp_session_range == "" ? null : each.value.bgp_session_range vpn_tunnel = google_compute_vpn_tunnel.tunnels[each.key].name diff --git a/modules/vpn_ha/variables.tf b/modules/vpn_ha/variables.tf index 9e16610..8337098 100644 --- a/modules/vpn_ha/variables.tf +++ b/modules/vpn_ha/variables.tf @@ -17,6 +17,7 @@ variable "peer_external_gateway" { description = "Configuration of an external VPN gateway to which this VPN is connected." type = object({ + name = optional(string) redundancy_type = string interfaces = list(object({ id = number @@ -74,6 +75,12 @@ variable "router_asn" { default = 64514 } +variable "keepalive_interval" { + description = "The interval in seconds between BGP keepalive messages that are sent to the peer." + type = number + default = 20 +} + variable "router_name" { description = "Name of router, leave blank to create one." type = string @@ -87,6 +94,7 @@ variable "tunnels" { address = string asn = number }) + bgp_session_name = optional(string) bgp_peer_options = object({ ip_address = string advertise_groups = list(string)