-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpn_gateway.tf
75 lines (64 loc) · 2.77 KB
/
vpn_gateway.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/******************************************
Locals configuration for module logic
*****************************************/
locals {
vpn_gateways = {
for network_region_label, router in local.routers : network_region_label => router
if lookup(router, "vpn_tunnels", {}) != {}
}
}
/******************************************
Create network VPN Gateways w/ static IPs
*****************************************/
resource "google_compute_address" "vpngw_static_ip" {
for_each = local.vpn_gateways
address_type = "EXTERNAL"
description = "${split("_", each.key)[0]}-${split("_", each.key)[1]}-router-${split("_", each.key)[2]}-vpngw public IP"
name = "${split("_", each.key)[0]}-${split("_", each.key)[1]}-router-${split("_", each.key)[2]}-vpngw-addr"
network_tier = "PREMIUM"
project = var.project_id
region = split("_", each.key)[1]
}
resource "google_compute_vpn_gateway" "vpngw" {
for_each = local.vpn_gateways
description = lookup(each.value, "description", null)
name = "${split("_", each.key)[0]}-${split("_", each.key)[1]}-router-${split("_", each.key)[2]}-vpngw"
network = google_compute_network.net[split("_", each.key)[0]].self_link
project = var.project_id
region = split("_", each.key)[1]
}
/******************************************
Create forwarding rules for VPN Gateways
*****************************************/
resource "google_compute_forwarding_rule" "vpngw_fr_esp" {
for_each = local.vpn_gateways
description = "Allow ESP protocol forwarding"
ip_address = google_compute_address.vpngw_static_ip[each.key].address
ip_protocol = "ESP"
name = "${google_compute_vpn_gateway.vpngw[each.key].name}-fr-esp"
project = var.project_id
region = split("_", each.key)[1]
target = google_compute_vpn_gateway.vpngw[each.key].self_link
}
resource "google_compute_forwarding_rule" "vpngw_fr_udp500" {
for_each = local.vpn_gateways
description = "Allow UDP/500 forwarding"
ip_address = google_compute_address.vpngw_static_ip[each.key].address
ip_protocol = "UDP"
name = "${google_compute_vpn_gateway.vpngw[each.key].name}-fr-udp500"
port_range = "500"
project = var.project_id
region = split("_", each.key)[1]
target = google_compute_vpn_gateway.vpngw[each.key].self_link
}
resource "google_compute_forwarding_rule" "vpngw_fr_udp4500" {
for_each = local.vpn_gateways
description = "Allow UDP/4500 forwarding"
ip_address = google_compute_address.vpngw_static_ip[each.key].address
ip_protocol = "UDP"
name = "${google_compute_vpn_gateway.vpngw[each.key].name}-fr-udp4500"
port_range = "4500"
project = var.project_id
region = split("_", each.key)[1]
target = google_compute_vpn_gateway.vpngw[each.key].self_link
}