...
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_network" "producer" {
19 provider = google-beta
20 name = "producer-vpc"
21 auto_create_subnetworks = false
22}
23
24resource "google_compute_subnetwork" "producer" {
25 provider = google-beta
26 name = "producer-subnet"
27 ip_cidr_range = "10.0.1.0/24"
28 region = "us-central1"
29 network = google_compute_network.producer.id
30}
31
32resource "google_compute_network" "consumer" {
33 provider = google-beta
34 name = "consumer-vpc"
35 auto_create_subnetworks = false
36}
37
38resource "google_compute_subnetwork" "consumer" {
39 provider = google-beta
40 name = "consumer-subnet"
41 ip_cidr_range = "10.0.2.0/24"
42 region = "us-central1"
43 network = google_compute_network.consumer.id
44}
45
46resource "google_compute_network_peering" "peering1" {
47 provider = google-beta
48 name = "peering-producer-to-consumer"
49 network = google_compute_network.consumer.id
50 peer_network = google_compute_network.producer.id
51}
52
53resource "google_compute_network_peering" "peering2" {
54 provider = google-beta
55 name = "peering-consumer-to-producer"
56 network = google_compute_network.producer.id
57 peer_network = google_compute_network.consumer.id
58}
59
60resource "google_compute_health_check" "hc" {
61 provider = google-beta
62 name = "proxy-health-check"
63 check_interval_sec = 1
64 timeout_sec = 1
65
66 tcp_health_check {
67 port = "80"
68 }
69}
70
71resource "google_compute_region_backend_service" "backend" {
72 provider = google-beta
73 name = "compute-backend"
74 region = "us-central1"
75 health_checks = [google_compute_health_check.hc.id]
76}
77
78resource "google_compute_forwarding_rule" "default" {
79 provider = google-beta
80 name = "compute-forwarding-rule"
81 region = "us-central1"
82
83 load_balancing_scheme = "INTERNAL"
84 backend_service = google_compute_region_backend_service.backend.id
85 all_ports = true
86 network = google_compute_network.producer.name
87 subnetwork = google_compute_subnetwork.producer.name
88}
89
90resource "google_compute_route" "route-ilb" {
91 provider = google-beta
92 name = "route-ilb"
93 dest_range = "0.0.0.0/0"
94 network = google_compute_network.consumer.name
95 next_hop_ilb = google_compute_forwarding_rule.default.ip_address
96 priority = 2000
97 tags = ["tag1", "tag2"]
98
99 depends_on = [
100 google_compute_network_peering.peering1,
101 google_compute_network_peering.peering2
102 ]
103}
104```
View as plain text