-
Notifications
You must be signed in to change notification settings - Fork 394
Feat: support for internal cross-regional load balancer #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bharathkkb
merged 41 commits into
terraform-google-modules:main
from
pawan1210:feat/internal-lb-cloud-run
Mar 21, 2025
Merged
Changes from 29 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
7bc5255
fix: fixed compression mode variable for internal lbs
pawan1210 47263c5
feat: added support for multiple forwarding rule creation based on su…
pawan1210 0e5d599
fix: exposed ip addresses of internal forwarding rules
pawan1210 46f0e62
chore: renamed description of network variable
pawan1210 8f223c6
feat: added example for internal cross regional lb
pawan1210 e0b61e8
fix: segregated internal self managed and managed for backward compat…
pawan1210 8f10e7e
fix: using updated variables in example
pawan1210 f3d770b
chore: lint
pawan1210 971e93d
chore: added readme.md file for example
pawan1210 ad2f3fe
fix: added default values for variables as per readme
pawan1210 31da11d
chore: updated frontend module's readme.md file
pawan1210 c07ac98
chore: updated naming convention for internal managed fw rules
pawan1210 4c0d422
fix: removed redundant compression_mode argument
pawan1210 4e7b103
fix: added ip_address_internal_managed_https output variable
pawan1210 f6f576e
fix: using hardcoded region values instead of variables
pawan1210 2ab0e8d
fix: fixed variable description
pawan1210 e19fdaa
chore: updated metadata.yaml and readme.md
pawan1210 1cf6c0d
chore: added newline
pawan1210 0267ef8
fix: added source registry
pawan1210 5fd7394
chore: updated metadata
pawan1210 a86f3d8
feat: added test
pawan1210 3515fdb
chore: lint
pawan1210 d0e98e8
chore: lint
pawan1210 f351557
fix: fixed module versions
pawan1210 72cb5b9
chore: removed unused dependencies
pawan1210 74f0cf5
fix: added wait for create
pawan1210 e97af8b
fix: added owner role in test setup
pawan1210 6435ec7
chore: updated metadata
pawan1210 66cfc36
fix: added correct dependencies for terraform destroy
pawan1210 9debd26
fix: removed owner roles and added service specific roles
pawan1210 b92d6f7
chore: lint
pawan1210 a04358e
fix: added service account admin role
pawan1210 263c89b
fix: updated the variable to use map instead of list
pawan1210 68227a7
fix: using modules instead of resources
pawan1210 4da3558
fix: added back the registry version
pawan1210 599fbcd
fix: using list of object type for the new variable
pawan1210 e1ee5e1
chore: updated variable description
pawan1210 abd2c6f
chore: added enums
pawan1210 abcc499
fix: using region instead of index for unique names
pawan1210 96495f4
chore: generate docs
pawan1210 973e17e
chore: added generic variable description
pawan1210 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| provider "google" { | ||
| project = var.project_id | ||
| } | ||
|
|
||
| provider "google-beta" { | ||
| project = var.project_id | ||
| } | ||
|
|
||
| resource "google_compute_network" "internal_lb_network" { | ||
| name = "int-lb-network" | ||
| auto_create_subnetworks = "false" | ||
| project = var.project_id | ||
| } | ||
|
|
||
| resource "google_compute_subnetwork" "internal_lb_subnet_a" { | ||
bharathkkb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name = "int-lb-subnet-a" | ||
| ip_cidr_range = "10.1.2.0/24" | ||
| network = google_compute_network.internal_lb_network.id | ||
| region = "us-east1" | ||
| project = var.project_id | ||
| depends_on = [google_compute_network.internal_lb_network] | ||
| } | ||
|
|
||
| resource "google_compute_subnetwork" "internal_lb_proxy_only_a" { | ||
| name = "int-lb-proxy-only-subnet-a" | ||
| ip_cidr_range = "10.129.0.0/23" | ||
| network = google_compute_network.internal_lb_network.id | ||
| purpose = "GLOBAL_MANAGED_PROXY" | ||
| region = "us-east1" | ||
| project = var.project_id | ||
| role = "ACTIVE" | ||
| depends_on = [google_compute_network.internal_lb_network] | ||
| } | ||
|
|
||
| resource "google_compute_subnetwork" "internal_lb_subnet_b" { | ||
| name = "int-lb-subnet-b" | ||
| ip_cidr_range = "10.1.3.0/24" | ||
| network = google_compute_network.internal_lb_network.id | ||
| region = "us-south1" | ||
| project = var.project_id | ||
| depends_on = [google_compute_network.internal_lb_network] | ||
| } | ||
|
|
||
| resource "google_compute_subnetwork" "internal_lb_proxy_only_b" { | ||
| name = "int-lb-proxy-only-subnet-b" | ||
| ip_cidr_range = "10.130.0.0/23" | ||
| network = google_compute_network.internal_lb_network.id | ||
| purpose = "GLOBAL_MANAGED_PROXY" | ||
| region = "us-south1" | ||
| project = var.project_id | ||
| role = "ACTIVE" | ||
| depends_on = [google_compute_network.internal_lb_network] | ||
| } | ||
|
|
||
| module "backend-service-region-a" { | ||
| source = "GoogleCloudPlatform/cloud-run/google//modules/v2" | ||
| version = "~> 0.16.3" | ||
| project_id = var.project_id | ||
| location = "us-central1" | ||
| service_name = "bs-a" | ||
| containers = [{ "container_name" = "", "container_image" = "gcr.io/cloudrun/hello" }] | ||
| members = ["allUsers"] | ||
| ingress = "INGRESS_TRAFFIC_INTERNAL_ONLY" | ||
| cloud_run_deletion_protection = false | ||
| enable_prometheus_sidecar = false | ||
| } | ||
|
|
||
| module "backend-service-region-b" { | ||
| source = "GoogleCloudPlatform/cloud-run/google//modules/v2" | ||
| version = "~> 0.16.3" | ||
| project_id = var.project_id | ||
| location = "us-west1" | ||
| service_name = "bs-b" | ||
| containers = [{ "container_name" = "", "container_image" = "gcr.io/cloudrun/hello" }] | ||
| members = ["allUsers"] | ||
| ingress = "INGRESS_TRAFFIC_INTERNAL_ONLY" | ||
| cloud_run_deletion_protection = false | ||
| enable_prometheus_sidecar = false | ||
| } | ||
|
|
||
| module "internal-lb-http-backend" { | ||
| source = "terraform-google-modules/lb-http/google//modules/backend" | ||
| version = "~> 12.0" | ||
|
|
||
| project_id = var.project_id | ||
| name = "int-lb-http-backend" | ||
| enable_cdn = false | ||
| load_balancing_scheme = "INTERNAL_MANAGED" | ||
| locality_lb_policy = "RANDOM" | ||
| serverless_neg_backends = [ | ||
| { region : "us-central1", type : "cloud-run", service_name : module.backend-service-region-a.service_name }, | ||
| { region : "us-west1", type : "cloud-run", service_name : module.backend-service-region-b.service_name } | ||
| ] | ||
| } | ||
|
|
||
| module "internal-lb-http-frontend" { | ||
| source = "terraform-google-modules/lb-http/google//modules/frontend" | ||
| version = "~> 12.0" | ||
|
|
||
| project_id = var.project_id | ||
| name = "int-lb-http-frontend" | ||
| url_map_input = module.internal-lb-http-backend.backend_service_info | ||
| network = google_compute_network.internal_lb_network.name | ||
| load_balancing_scheme = "INTERNAL_MANAGED" | ||
| internal_forwarding_rule_subnetworks = [ | ||
| google_compute_subnetwork.internal_lb_subnet_a.id, | ||
pawan1210 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| google_compute_subnetwork.internal_lb_subnet_b.id | ||
| ] | ||
| depends_on = [google_compute_subnetwork.internal_lb_proxy_only_a, google_compute_subnetwork.internal_lb_proxy_only_b] | ||
| } | ||
|
|
||
| resource "google_vpc_access_connector" "internal_lb_vpc_connector" { | ||
| provider = google-beta | ||
| project = var.project_id | ||
| name = "int-lb-vpc-connector" | ||
| region = "us-east1" | ||
| ip_cidr_range = "10.8.0.0/28" | ||
| network = google_compute_network.internal_lb_network.name | ||
| max_throughput = 500 | ||
| min_throughput = 300 | ||
| } | ||
|
|
||
| module "frontend-service-a" { | ||
| source = "GoogleCloudPlatform/cloud-run/google//modules/v2" | ||
| version = "~> 0.16.3" | ||
| project_id = var.project_id | ||
| location = "us-east1" | ||
| service_name = "fs-a" | ||
| containers = [{ "env_vars" : { "TARGET_IP" : module.internal-lb-http-frontend.ip_address_internal_managed_http[0] }, "ports" = { "container_port" = 80, "name" = "http1" }, "container_name" = "", "container_image" = "gcr.io/design-center-container-repo/redirect-traffic:latest-2002" }] | ||
| members = ["allUsers"] | ||
| vpc_access = { | ||
| connector = google_vpc_access_connector.internal_lb_vpc_connector.id | ||
| egress = "ALL_TRAFFIC" | ||
| } | ||
| ingress = "INGRESS_TRAFFIC_ALL" | ||
| cloud_run_deletion_protection = false | ||
| enable_prometheus_sidecar = false | ||
| depends_on = [google_vpc_access_connector.internal_lb_vpc_connector] | ||
| } | ||
|
|
||
| module "frontend-service-b" { | ||
| source = "GoogleCloudPlatform/cloud-run/google//modules/v2" | ||
| version = "~> 0.16.3" | ||
| project_id = var.project_id | ||
| location = "us-east1" | ||
| service_name = "fs-b" | ||
| containers = [{ "env_vars" : { "TARGET_IP" : module.internal-lb-http-frontend.ip_address_internal_managed_http[1] }, "ports" = { "container_port" = 80, "name" = "http1" }, "container_name" = "", "container_image" = "gcr.io/design-center-container-repo/redirect-traffic:latest-2002" }] | ||
| members = ["allUsers"] | ||
| vpc_access = { | ||
| connector = google_vpc_access_connector.internal_lb_vpc_connector.id | ||
| egress = "ALL_TRAFFIC" | ||
| } | ||
| ingress = "INGRESS_TRAFFIC_ALL" | ||
| cloud_run_deletion_protection = false | ||
| enable_prometheus_sidecar = false | ||
| } | ||
bharathkkb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| output "external_cloudrun_uris" { | ||
| description = "List of URIs for the frontend Cloud Run services" | ||
| value = [module.frontend-service-a.service_uri, module.frontend-service-b.service_uri] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # HTTP Internal Regional Load Balancer Example | ||
|
|
||
| This example creates a simple application with below components. | ||
|
|
||
| * *Frontend Service*: Two cloud-run services to send request to internal cross-regional load balancers. The cloud-run service uses VPC access connector to send the request to the internal load balancer. | ||
| * *Internal Load Balancer*: An internal cross-regional load balancer to distribute traffic to internal cloud run services. | ||
| * *Backend Service*: Two cloud-run services to run the actual application code. These can be accessed within internal traffic. The internal Application Load Balancer is considered internal traffic. | ||
|
|
||
|
|
||
| The `google_compute_backend_service` and its dependencies are created as part of `backend` module. | ||
| The forwarding rules and its dependecies are created as part of `frontend` module. | ||
|
|
||
| <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
| ## Inputs | ||
|
|
||
| | Name | Description | Type | Default | Required | | ||
| |------|-------------|------|---------|:--------:| | ||
| | project\_id | n/a | `string` | n/a | yes | | ||
|
|
||
| <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| variable "project_id" { | ||
| type = string | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.