Skip to content

Commit

Permalink
chore(docs): Added Shared VPC forwarding rule example (#344)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
betsy-lichtenberg authored Jan 5, 2022
1 parent a7b91bc commit 1e2d68a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
24 changes: 16 additions & 8 deletions examples/basic_shared_vpc/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Simple shared VPC Project
# Shared VPC network

This example:

* Enables shared VPC on a host project
* Attaches a service project
* Reserves an internal IP address in a subnet of a Shared VPC network
* Creates a VM instance
* Enables Shared VPC on a host project

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

* In the host project's shared subnet, creates the following service project
resources:

* Reserved internal IP address. The IP address can come from the range of
available addresses in the shared subnet, or you can specify an address.
* VM instance that uses the reserved IP address and has an interface in
the shared subnetwork.
* VM instance that uses an ephemeral IP address and has an interface in
the shared subnetwork.
* VM instance template that creates an interface in
the shared subnetwork.
* Forwarding rule in the shared VPC network and subnetwork, along with
a backend service and a health check.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs
Expand Down
40 changes: 38 additions & 2 deletions examples/basic_shared_vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ resource "google_compute_shared_vpc_service_project" "service1" {
}
# [END vpc_shared_vpc_service_project_attach]

# [START compute_shared_data]
# [START compute_shared_data_network]
data "google_compute_network" "network" {
name = "my-network-123"
project = var.project
}
# [END compute_shared_data_network]

# [START compute_shared_data_subnet]
data "google_compute_subnetwork" "subnet" {
name = "my-subnet-123"
project = var.project
region = "us-central1"
}
# [END compute_shared_data]
# [END compute_shared_data_subnet]

# [START compute_shared_internal_ip_create]
resource "google_compute_address" "internal" {
Expand Down Expand Up @@ -96,3 +103,32 @@ resource "google_compute_instance_template" "default" {
}
}
# [END compute_shared_instance_template_create]

resource "google_compute_region_health_check" "default" {
name = "l4-ilb-hc"
region = "europe-west1"
http_health_check {
port = "80"
}
}
resource "google_compute_region_backend_service" "default" {
name = "l4-ilb-backend-subnet"
region = "europe-west1"
protocol = "TCP"
load_balancing_scheme = "INTERNAL"
health_checks = [google_compute_region_health_check.default.id]
}
# [START compute_shared_forwarding_rule_l4_ilb]
resource "google_compute_forwarding_rule" "default" {
project = var.service_project
name = "l4-ilb-forwarding-rule"
backend_service = google_compute_region_backend_service.default.id
region = "europe-west1"
ip_protocol = "TCP"
load_balancing_scheme = "INTERNAL"
all_ports = true
allow_global_access = true
network = data.google_compute_network.network.self_link
subnetwork = data.google_compute_subnetwork.subnet.self_link
}
# [END compute_shared_forwarding_rule_l4_ilb]

0 comments on commit 1e2d68a

Please sign in to comment.