Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 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 Mar 6, 2025
47263c5
feat: added support for multiple forwarding rule creation based on su…
pawan1210 Mar 6, 2025
0e5d599
fix: exposed ip addresses of internal forwarding rules
pawan1210 Mar 6, 2025
46f0e62
chore: renamed description of network variable
pawan1210 Mar 6, 2025
8f223c6
feat: added example for internal cross regional lb
pawan1210 Mar 6, 2025
e0b61e8
fix: segregated internal self managed and managed for backward compat…
pawan1210 Mar 7, 2025
8f10e7e
fix: using updated variables in example
pawan1210 Mar 7, 2025
f3d770b
chore: lint
pawan1210 Mar 7, 2025
971e93d
chore: added readme.md file for example
pawan1210 Mar 7, 2025
ad2f3fe
fix: added default values for variables as per readme
pawan1210 Mar 7, 2025
31da11d
chore: updated frontend module's readme.md file
pawan1210 Mar 7, 2025
c07ac98
chore: updated naming convention for internal managed fw rules
pawan1210 Mar 10, 2025
4c0d422
fix: removed redundant compression_mode argument
pawan1210 Mar 10, 2025
4e7b103
fix: added ip_address_internal_managed_https output variable
pawan1210 Mar 11, 2025
f6f576e
fix: using hardcoded region values instead of variables
pawan1210 Mar 11, 2025
2ab0e8d
fix: fixed variable description
pawan1210 Mar 11, 2025
e19fdaa
chore: updated metadata.yaml and readme.md
pawan1210 Mar 11, 2025
1cf6c0d
chore: added newline
pawan1210 Mar 12, 2025
0267ef8
fix: added source registry
pawan1210 Mar 12, 2025
5fd7394
chore: updated metadata
pawan1210 Mar 12, 2025
a86f3d8
feat: added test
pawan1210 Mar 12, 2025
3515fdb
chore: lint
pawan1210 Mar 12, 2025
d0e98e8
chore: lint
pawan1210 Mar 12, 2025
f351557
fix: fixed module versions
pawan1210 Mar 12, 2025
72cb5b9
chore: removed unused dependencies
pawan1210 Mar 12, 2025
74f0cf5
fix: added wait for create
pawan1210 Mar 12, 2025
e97af8b
fix: added owner role in test setup
pawan1210 Mar 12, 2025
6435ec7
chore: updated metadata
pawan1210 Mar 12, 2025
66cfc36
fix: added correct dependencies for terraform destroy
pawan1210 Mar 13, 2025
9debd26
fix: removed owner roles and added service specific roles
pawan1210 Mar 17, 2025
b92d6f7
chore: lint
pawan1210 Mar 17, 2025
a04358e
fix: added service account admin role
pawan1210 Mar 17, 2025
263c89b
fix: updated the variable to use map instead of list
pawan1210 Mar 19, 2025
68227a7
fix: using modules instead of resources
pawan1210 Mar 19, 2025
4da3558
fix: added back the registry version
pawan1210 Mar 19, 2025
599fbcd
fix: using list of object type for the new variable
pawan1210 Mar 20, 2025
e1ee5e1
chore: updated variable description
pawan1210 Mar 21, 2025
abd2c6f
chore: added enums
pawan1210 Mar 21, 2025
abcc499
fix: using region instead of index for unique names
pawan1210 Mar 21, 2025
96495f4
chore: generate docs
pawan1210 Mar 21, 2025
973e17e
chore: added generic variable description
pawan1210 Mar 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ steps:
- verify lb-http-separate-frontend-and-backend
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSeparateFrontendAndBackend --stage teardown --verbose']
# Internal cross regional http load balancer with cloud-run
- id: apply internal-lb-http
waitFor:
- create
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestInternalLbCloudRun --stage apply --verbose']
- id: verify internal-lb-http
waitFor:
- apply internal-lb-http
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'sleep 360 && cft test run TestInternalLbCloudRun --stage verify --verbose']
- id: teardown internal-lb-http
waitFor:
- verify internal-lb-http
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestInternalLbCloudRun --stage teardown --verbose']
tags:
- 'ci'
- 'integration'
Expand Down
173 changes: 173 additions & 0 deletions examples/internal-lb-cloud-run/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/**
* 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
}

module "internal-lb-network" {
source = "terraform-google-modules/network/google//modules/vpc"
version = "~> 10.0.0"
project_id = var.project_id
network_name = "int-lb-network"
auto_create_subnetworks = false
}

module "internal-lb-subnet" {
source = "terraform-google-modules/network/google//modules/subnets"
version = "~> 10.0.0"

subnets = [
{
subnet_name = "int-lb-subnet-a"
subnet_ip = "10.1.2.0/24"
subnet_region = "us-east1"
},
{
subnet_name = "int-lb-proxy-only-subnet-a"
subnet_ip = "10.129.0.0/23"
subnet_region = "us-east1"
purpose = "GLOBAL_MANAGED_PROXY"
role = "ACTIVE"
},
{
subnet_name = "int-lb-subnet-b"
subnet_ip = "10.1.3.0/24"
subnet_region = "us-south1"
},
{
subnet_name = "int-lb-proxy-only-subnet-b",
subnet_ip = "10.130.0.0/23"
subnet_region = "us-south1"
purpose = "GLOBAL_MANAGED_PROXY"
role = "ACTIVE"
}
]

network_name = module.internal-lb-network.network_name
project_id = var.project_id
depends_on = [module.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 = module.internal-lb-network.network_name
load_balancing_scheme = "INTERNAL_MANAGED"
internal_forwarding_rule_configs = {
"1" : {
"subnetwork" : module.internal-lb-subnet.subnets["us-east1/int-lb-subnet-a"].id
},
"2" : {
"subnetwork" : module.internal-lb-subnet.subnets["us-south1/int-lb-subnet-b"].id
}
}
}

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 = module.internal-lb-network.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
}
20 changes: 20 additions & 0 deletions examples/internal-lb-cloud-run/outputs.tf
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]
}
20 changes: 20 additions & 0 deletions examples/internal-lb-cloud-run/readme.md
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 -->
19 changes: 19 additions & 0 deletions examples/internal-lb-cloud-run/variables.tf
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
}
5 changes: 5 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ spec:
location: examples/https-gke
- name: https-redirect
location: examples/https-redirect
- name: internal-lb-cloud-run
location: examples/internal-lb-cloud-run
- name: lb-http-separate-frontend-and-backend
location: examples/lb-http-separate-frontend-and-backend
- name: mig-nat-http-lb
Expand Down Expand Up @@ -338,6 +340,8 @@ spec:
- roles/run.admin
- roles/iam.serviceAccountUser
- roles/certificatemanager.owner
- roles/vpcaccess.admin
- roles/iam.serviceAccountAdmin
services:
- cloudresourcemanager.googleapis.com
- storage-api.googleapis.com
Expand All @@ -346,6 +350,7 @@ spec:
- run.googleapis.com
- iam.googleapis.com
- certificatemanager.googleapis.com
- vpcaccess.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 6.0, < 7"
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ resource "google_compute_backend_service" "default" {
description = var.description
connection_draining_timeout_sec = var.connection_draining_timeout_sec
enable_cdn = var.enable_cdn
compression_mode = var.compression_mode
compression_mode = var.load_balancing_scheme == "INTERNAL_SELF_MANAGED" || var.load_balancing_scheme == "INTERNAL_MANAGED" ? null : var.compression_mode
custom_request_headers = var.custom_request_headers
custom_response_headers = var.custom_response_headers
session_affinity = var.session_affinity
Expand Down
5 changes: 5 additions & 0 deletions modules/backend/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
location: examples/https-gke
- name: https-redirect
location: examples/https-redirect
- name: internal-lb-cloud-run
location: examples/internal-lb-cloud-run
- name: lb-http-separate-frontend-and-backend
location: examples/lb-http-separate-frontend-and-backend
- name: mig-nat-http-lb
Expand Down Expand Up @@ -305,6 +307,8 @@ spec:
- roles/run.admin
- roles/iam.serviceAccountUser
- roles/certificatemanager.owner
- roles/vpcaccess.admin
- roles/iam.serviceAccountAdmin
services:
- cloudresourcemanager.googleapis.com
- storage-api.googleapis.com
Expand All @@ -313,6 +317,7 @@ spec:
- run.googleapis.com
- iam.googleapis.com
- certificatemanager.googleapis.com
- vpcaccess.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 6.0, < 7"
Expand Down
5 changes: 5 additions & 0 deletions modules/dynamic_backends/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
location: examples/https-gke
- name: https-redirect
location: examples/https-redirect
- name: internal-lb-cloud-run
location: examples/internal-lb-cloud-run
- name: lb-http-separate-frontend-and-backend
location: examples/lb-http-separate-frontend-and-backend
- name: mig-nat-http-lb
Expand Down Expand Up @@ -330,6 +332,8 @@ spec:
- roles/run.admin
- roles/iam.serviceAccountUser
- roles/certificatemanager.owner
- roles/vpcaccess.admin
- roles/iam.serviceAccountAdmin
services:
- cloudresourcemanager.googleapis.com
- storage-api.googleapis.com
Expand All @@ -338,6 +342,7 @@ spec:
- run.googleapis.com
- iam.googleapis.com
- certificatemanager.googleapis.com
- vpcaccess.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 6.0, < 7"
Expand Down
5 changes: 4 additions & 1 deletion modules/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ This module creates `HTTP(S) forwarding rule` and its dependencies. This modules
| http\_port | The port for the HTTP load balancer | `number` | `80` | no |
| https\_port | The port for the HTTPS load balancer | `number` | `443` | no |
| https\_redirect | Set to `true` to enable https redirect on the lb. | `bool` | `false` | no |
| internal\_forwarding\_rule\_configs | Map of internal managed forwarding rule configs. One of 'address' or 'subnetwork' is required for each. | <pre>map(object({<br> address = optional(string)<br> subnetwork = optional(string)<br> }))</pre> | `{}` | no |
| ipv6\_address | An existing IPv6 address to use (the actual IP address value) | `string` | `null` | no |
| labels | The labels to attach to resources created by this module | `map(string)` | `{}` | no |
| load\_balancing\_scheme | Load balancing scheme type (EXTERNAL for classic external load balancer, EXTERNAL\_MANAGED for Envoy-based load balancer, and INTERNAL\_SELF\_MANAGED for traffic director) | `string` | `"EXTERNAL_MANAGED"` | no |
| managed\_ssl\_certificate\_domains | Create Google-managed SSL certificates for specified domains. Requires `ssl` to be set to `true` | `list(string)` | `[]` | no |
| name | Name for the forwarding rule and prefix for supporting resources | `string` | n/a | yes |
| network | Network for INTERNAL\_SELF\_MANAGED load balancing scheme | `string` | `"default"` | no |
| network | Network for INTERNAL\_SELF\_MANAGED/INTERNAL\_MANAGED load balancing scheme | `string` | `"default"` | no |
| private\_key | Content of the private SSL key. Requires `ssl` to be set to `true` and `create_ssl_certificate` set to `true` | `string` | `null` | no |
| project\_id | The project to deploy to, if not set the default provider project is used. | `string` | n/a | yes |
| quic | Specifies the QUIC override policy for this resource. Set true to enable HTTP/3 and Google QUIC support, false to disable both. Defaults to null which enables support for HTTP/3 only. | `bool` | `null` | no |
Expand All @@ -44,6 +45,8 @@ This module creates `HTTP(S) forwarding rule` and its dependencies. This modules
| external\_ipv6\_address | The external IPv6 assigned to the global fowarding rule. |
| http\_proxy | The HTTP proxy used by this module. |
| https\_proxy | The HTTPS proxy used by this module. |
| ip\_address\_internal\_managed\_http | The internal/external IP addresses assigned to the HTTP forwarding rules. |
| ip\_address\_internal\_managed\_https | The internal/external IP addresses assigned to the HTTPS forwarding rules. |
| ipv6\_enabled | Whether IPv6 configuration is enabled on this load-balancer |
| ssl\_certificate\_created | The SSL certificate create from key/pem |
| url\_map | The default URL map used by this module. |
Expand Down
Loading