Skip to content

Commit 1e2d68a

Browse files
chore(docs): Added Shared VPC forwarding rule example (#344)
* Added Shared VPC forwarding rule example * Updated README * Fixed tf fmt * Made shared data region tags specific so that we don't have to include both the network and subnetwork when both are not needed
1 parent a7b91bc commit 1e2d68a

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

examples/basic_shared_vpc/README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
# Simple shared VPC Project
1+
# Shared VPC network
22

33
This example:
44

5-
* Enables shared VPC on a host project
6-
* Attaches a service project
7-
* Reserves an internal IP address in a subnet of a Shared VPC network
8-
* Creates a VM instance
5+
* Enables Shared VPC on a host project
96

10-
The IP address configuration object is created in the service
11-
project. Its value can come from the range of available addresses in
12-
the chosen shared subnet, or you can specify an address.
7+
* Attaches a service project
138

9+
* In the host project's shared subnet, creates the following service project
10+
resources:
11+
12+
* Reserved internal IP address. The IP address can come from the range of
13+
available addresses in the shared subnet, or you can specify an address.
14+
* VM instance that uses the reserved IP address and has an interface in
15+
the shared subnetwork.
16+
* VM instance that uses an ephemeral IP address and has an interface in
17+
the shared subnetwork.
18+
* VM instance template that creates an interface in
19+
the shared subnetwork.
20+
* Forwarding rule in the shared VPC network and subnetwork, along with
21+
a backend service and a health check.
1422

1523
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1624
## Inputs

examples/basic_shared_vpc/main.tf

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ resource "google_compute_shared_vpc_service_project" "service1" {
2727
}
2828
# [END vpc_shared_vpc_service_project_attach]
2929

30-
# [START compute_shared_data]
30+
# [START compute_shared_data_network]
31+
data "google_compute_network" "network" {
32+
name = "my-network-123"
33+
project = var.project
34+
}
35+
# [END compute_shared_data_network]
36+
37+
# [START compute_shared_data_subnet]
3138
data "google_compute_subnetwork" "subnet" {
3239
name = "my-subnet-123"
3340
project = var.project
3441
region = "us-central1"
3542
}
36-
# [END compute_shared_data]
43+
# [END compute_shared_data_subnet]
3744

3845
# [START compute_shared_internal_ip_create]
3946
resource "google_compute_address" "internal" {
@@ -96,3 +103,32 @@ resource "google_compute_instance_template" "default" {
96103
}
97104
}
98105
# [END compute_shared_instance_template_create]
106+
107+
resource "google_compute_region_health_check" "default" {
108+
name = "l4-ilb-hc"
109+
region = "europe-west1"
110+
http_health_check {
111+
port = "80"
112+
}
113+
}
114+
resource "google_compute_region_backend_service" "default" {
115+
name = "l4-ilb-backend-subnet"
116+
region = "europe-west1"
117+
protocol = "TCP"
118+
load_balancing_scheme = "INTERNAL"
119+
health_checks = [google_compute_region_health_check.default.id]
120+
}
121+
# [START compute_shared_forwarding_rule_l4_ilb]
122+
resource "google_compute_forwarding_rule" "default" {
123+
project = var.service_project
124+
name = "l4-ilb-forwarding-rule"
125+
backend_service = google_compute_region_backend_service.default.id
126+
region = "europe-west1"
127+
ip_protocol = "TCP"
128+
load_balancing_scheme = "INTERNAL"
129+
all_ports = true
130+
allow_global_access = true
131+
network = data.google_compute_network.network.self_link
132+
subnetwork = data.google_compute_subnetwork.subnet.self_link
133+
}
134+
# [END compute_shared_forwarding_rule_l4_ilb]

0 commit comments

Comments
 (0)