Added VPN GW and Tunnel modules.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
data "google_compute_vpn_gateway" "gw" {
|
||||
name = var.gw_name
|
||||
}
|
||||
|
||||
locals {
|
||||
vpc_name = regex("networks/([^/]+)$", data.google_compute_vpn_gateway.gw.network)[0]
|
||||
}
|
||||
|
||||
data google_compute_network network {
|
||||
name = local.vpc_name
|
||||
}
|
||||
|
||||
resource "google_compute_vpn_tunnel" "tunnel" {
|
||||
name = var.name
|
||||
target_vpn_gateway = data.google_compute_vpn_gateway.gw.id
|
||||
|
||||
shared_secret = var.shared_secret
|
||||
peer_ip = var.peer_ip
|
||||
ike_version = 2
|
||||
|
||||
local_traffic_selector = concat(var.local_selectors, ["35.199.192.0/19"])
|
||||
remote_traffic_selector = var.remote_selectors
|
||||
}
|
||||
|
||||
resource "google_compute_route" "route_to_remote_network" {
|
||||
count = length(var.remote_selectors)
|
||||
name = "${data.google_compute_network.network.name}-to-${replace(var.remote_selectors[count.index], "/[./]/", "-")}"
|
||||
network = data.google_compute_network.network.name
|
||||
dest_range = var.remote_selectors[count.index]
|
||||
next_hop_vpn_tunnel = google_compute_vpn_tunnel.tunnel.id
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
variable "name" {
|
||||
description = "Name of the VPN tunnel"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "gw_name" {
|
||||
description = "The name of the VPN gateway"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "shared_secret" {
|
||||
description = "Shared secret for the VPN tunnel"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "peer_ip" {
|
||||
description = "IP address of the peer VPN gateway"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "local_selectors" {
|
||||
description = "Local traffic selectors for the VPN tunnel"
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "remote_selectors" {
|
||||
description = "Remote traffic selectors for the VPN tunnel"
|
||||
type = list(string)
|
||||
}
|
||||
Reference in New Issue
Block a user