...
1/**
2 * Copyright 2022 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17```hcl
18resource "google_compute_vpn_tunnel" "tunnel1" {
19 provider = google-beta
20 name = "tunnel-1"
21 peer_ip = "15.0.0.120"
22 shared_secret = "a secret message"
23
24 target_vpn_gateway = google_compute_vpn_gateway.target_gateway.id
25
26 depends_on = [
27 google_compute_forwarding_rule.fr_esp,
28 google_compute_forwarding_rule.fr_udp500,
29 google_compute_forwarding_rule.fr_udp4500,
30 ]
31
32 labels = {
33 foo = "bar"
34 }
35}
36
37resource "google_compute_vpn_gateway" "target_gateway" {
38 provider = google-beta
39 name = "vpn-1"
40 network = google_compute_network.network1.id
41}
42
43resource "google_compute_network" "network1" {
44 provider = google-beta
45 name = "network-1"
46}
47
48resource "google_compute_address" "vpn_static_ip" {
49 provider = google-beta
50 name = "vpn-static-ip"
51}
52
53resource "google_compute_forwarding_rule" "fr_esp" {
54 provider = google-beta
55 name = "fr-esp"
56 ip_protocol = "ESP"
57 ip_address = google_compute_address.vpn_static_ip.address
58 target = google_compute_vpn_gateway.target_gateway.id
59}
60
61resource "google_compute_forwarding_rule" "fr_udp500" {
62 provider = google-beta
63 name = "fr-udp500"
64 ip_protocol = "UDP"
65 port_range = "500"
66 ip_address = google_compute_address.vpn_static_ip.address
67 target = google_compute_vpn_gateway.target_gateway.id
68}
69
70resource "google_compute_forwarding_rule" "fr_udp4500" {
71 provider = google-beta
72 name = "fr-udp4500"
73 ip_protocol = "UDP"
74 port_range = "4500"
75 ip_address = google_compute_address.vpn_static_ip.address
76 target = google_compute_vpn_gateway.target_gateway.id
77}
78
79resource "google_compute_route" "route1" {
80 provider = google-beta
81 name = "route1"
82 network = google_compute_network.network1.name
83 dest_range = "15.0.0.0/24"
84 priority = 1000
85
86 next_hop_vpn_tunnel = google_compute_vpn_tunnel.tunnel1.id
87}
88
89provider "google-beta" {
90 region = "us-central1"
91 zone = "us-central1-a"
92
93}
94```
View as plain text