-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgcp.tf
104 lines (86 loc) · 2.81 KB
/
gcp.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
resource "google_compute_vpn_gateway" "gcp" {
name = "gcp-vpn"
network = "${var.gcp_network}"
region = "${var.gcp_region}"
}
resource "google_compute_address" "vpn_static_ip" {
name = "vpn-static-ip"
region = "${var.gcp_region}"
}
resource "google_compute_forwarding_rule" "fr_esp" {
name = "fr-esp"
region = "${var.gcp_region}"
ip_protocol = "ESP"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.gcp.self_link}"
}
resource "google_compute_forwarding_rule" "fr_udp500" {
name = "fr-udp500"
region = "${var.gcp_region}"
ip_protocol = "UDP"
port_range = "500-500"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.gcp.self_link}"
}
resource "google_compute_forwarding_rule" "fr_udp4500" {
name = "fr-udp4500"
region = "${var.gcp_region}"
ip_protocol = "UDP"
port_range = "4500-4500"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.gcp.self_link}"
}
resource "google_compute_vpn_tunnel" "tunnel1" {
name = "gcp-tunnel-1"
ike_version = "1"
region = "${var.gcp_region}"
peer_ip = "${aws_vpn_connection.main.tunnel1_address}"
shared_secret = "${aws_vpn_connection.main.tunnel1_preshared_key}"
target_vpn_gateway = "${google_compute_vpn_gateway.gcp.self_link}"
depends_on = [
"google_compute_forwarding_rule.fr_esp",
"google_compute_forwarding_rule.fr_udp500",
"google_compute_forwarding_rule.fr_udp4500",
]
}
resource "google_compute_route" "gcp_route1" {
name = "gcp-route1"
network = "${var.gcp_network}"
dest_range = "${var.aws_cidr}"
priority = 1000
next_hop_vpn_tunnel = "${google_compute_vpn_tunnel.tunnel1.self_link}"
}
resource "google_compute_vpn_tunnel" "tunnel2" {
name = "gcp-tunnel-2"
ike_version = "1"
region = "${var.gcp_region}"
peer_ip = "${aws_vpn_connection.main.tunnel2_address}"
shared_secret = "${aws_vpn_connection.main.tunnel2_preshared_key}"
target_vpn_gateway = "${google_compute_vpn_gateway.gcp.self_link}"
depends_on = [
"google_compute_forwarding_rule.fr_esp",
"google_compute_forwarding_rule.fr_udp500",
"google_compute_forwarding_rule.fr_udp4500",
]
}
resource "google_compute_route" "gcp_route2" {
name = "gcp-route2"
network = "${var.gcp_network}"
dest_range = "${var.aws_cidr}"
priority = 1000
next_hop_vpn_tunnel = "${google_compute_vpn_tunnel.tunnel2.self_link}"
}
resource "google_compute_firewall" "aws_vpn" {
name = "aws"
network = "${var.gcp_network}"
source_ranges = ["${var.aws_cidr}"]
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
}
allow {
protocol = "udp"
}
}