-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgcp_networking.tf
185 lines (148 loc) · 5.26 KB
/
gcp_networking.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* ########## Network Setup ############## */
resource "google_compute_network" "gcp-network" {
name = "gcp-network"
auto_create_subnetworks = "true"
}
resource "google_compute_firewall" "allow-icmp" {
name = "${google_compute_network.gcp-network.name}-allow-icmp"
network = "${google_compute_network.gcp-network.name}"
allow {
protocol = "icmp"
}
source_ranges = [
"0.0.0.0/0"
]
}
resource "google_compute_firewall" "allow-internal" {
name = "${google_compute_network.gcp-network.name}-allow-internal"
network = "${google_compute_network.gcp-network.name}"
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
ports = ["0-65535"]
}
allow {
protocol = "udp"
ports = ["0-65535"]
}
source_ranges = [
"${var.gcp_network_cidr}"
]
}
resource "google_compute_firewall" "allow-ssh" {
name = "${google_compute_network.gcp-network.name}-allow-ssh"
network = "${google_compute_network.gcp-network.name}"
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = [
"0.0.0.0/0"
]
}
/* ########## VPN Connection ############## */
resource "google_compute_vpn_gateway" "target_gateway" {
name = "gcp-vpn-${var.gcp_region}"
network = "${google_compute_network.gcp-network.self_link}"
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"
ip_protocol = "ESP"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
}
resource "google_compute_forwarding_rule" "fr_udp500" {
name = "fr-udp500"
ip_protocol = "UDP"
port_range = "500-500"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
}
resource "google_compute_forwarding_rule" "fr_udp4500" {
name = "fr-udp4500"
ip_protocol = "UDP"
port_range = "4500-4500"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
}
/* ########## VPN Tunnel 1 ############## */
resource "google_compute_vpn_tunnel" "tunnel1" {
name = "tunnel1"
peer_ip = "${aws_vpn_connection.aws-vpn-connection1.tunnel1_address}"
shared_secret = "${aws_vpn_connection.aws-vpn-connection1.tunnel1_preshared_key}"
ike_version = 1
target_vpn_gateway = "${google_compute_vpn_gateway.target_gateway.self_link}"
router = "${google_compute_router.gcp-router1.name}"
depends_on = [
"google_compute_forwarding_rule.fr_esp",
"google_compute_forwarding_rule.fr_udp500",
"google_compute_forwarding_rule.fr_udp4500",
]
}
resource "google_compute_router" "gcp-router1" {
name = "gcp-router1"
region = "${var.gcp_region}"
network = "${google_compute_network.gcp-network.self_link}"
bgp {
asn = "${aws_customer_gateway.aws-customer-gateway.bgp_asn}"
}
}
resource "google_compute_router_peer" "router1_peer" {
name = "gcp-to-aws-bgp1"
router = "${google_compute_router.gcp-router1.name}"
region = "${google_compute_router.gcp-router1.region}"
ip_address = "${var.TUN1_VPN_GW_INSIDE_IP}"
asn = "${var.TUN1_VPN_GW_ASN}"
interface = "${google_compute_router_interface.router_interface1.name}"
}
resource "google_compute_router_interface" "router_interface1" {
name = "gcp-to-aws-interface1"
router = "${google_compute_router.gcp-router1.name}"
region = "${google_compute_router.gcp-router1.region}"
ip_range = "${var.TUN1_CUSTOMER_GW_INSIDE_IP}/${var.TUN1_CUSTOMER_GW_INSIDE_NETWORK_CIDR}"
vpn_tunnel = "${google_compute_vpn_tunnel.tunnel1.name}"
}
/* ########## VPN Tunnel 2 ############## */
resource "google_compute_vpn_tunnel" "tunnel2" {
name = "tunnel2"
peer_ip = "${aws_vpn_connection.aws-vpn-connection1.tunnel2_address}"
shared_secret = "${aws_vpn_connection.aws-vpn-connection1.tunnel2_preshared_key}"
ike_version = 1
target_vpn_gateway = "${google_compute_vpn_gateway.target_gateway.self_link}"
router = "${google_compute_router.gcp-router2.name}"
depends_on = [
"google_compute_forwarding_rule.fr_esp",
"google_compute_forwarding_rule.fr_udp500",
"google_compute_forwarding_rule.fr_udp4500",
]
}
resource "google_compute_router" "gcp-router2" {
name = "gcp-router2"
region = "${var.gcp_region}"
network = "${google_compute_network.gcp-network.self_link}"
bgp {
asn = "${aws_customer_gateway.aws-customer-gateway.bgp_asn}"
}
}
resource "google_compute_router_peer" "router2_peer" {
name = "gcp-to-aws-bgp2"
router = "${google_compute_router.gcp-router2.name}"
region = "${google_compute_router.gcp-router2.region}"
ip_address = "${var.TUN2_VPN_GW_INSIDE_IP}"
asn = "${var.TUN2_VPN_GW_ASN}"
interface = "${google_compute_router_interface.router_interface2.name}"
}
resource "google_compute_router_interface" "router_interface2" {
name = "gcp-to-aws-interface2"
router = "${google_compute_router.gcp-router2.name}"
region = "${google_compute_router.gcp-router2.region}"
ip_range = "${var.TUN2_CUSTOMER_GW_INSIDE_IP}/${var.TUN2_CUSTOMER_GW_INSIDE_NETWORK_CIDR}"
vpn_tunnel = "${google_compute_vpn_tunnel.tunnel2.name}"
}