Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.25
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.25.4
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
REGISTRY_URL := gcr.io/cloud-foundation-cicd

Expand Down
21 changes: 21 additions & 0 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,27 @@ steps:
- verify internal-lb-http gce-mig
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestInternalLbGCEMIG --stage teardown --verbose']
# Backend Service with IAP Enabled
- id: init backend-with-iap
waitFor:
- teardown internal-lb-http gce-mig
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/backend-with-iap --stage init --verbose']
- id: apply backend-with-iap
waitFor:
- init backend-with-iap
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/backend-with-iap --stage apply --verbose']
- id: verify backend-with-iap
waitFor:
- apply backend-with-iap
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/backend-with-iap --stage verify --verbose']
- id: teardown backend-with-iap
waitFor:
- verify backend-with-iap
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/backend-with-iap --stage teardown --verbose']
tags:
- 'ci'
- 'integration'
Expand Down
36 changes: 36 additions & 0 deletions examples/backend-with-iap/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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.
*/

module "lb-backend-iap" {
source = "terraform-google-modules/lb-http/google//modules/backend"
version = "~> 12.0"

project_id = var.project_id
name = "backend-with-iap"
iap_config = {
enable = true
iap_members = ["user:[email protected]"]
}
}

module "lb-frontend" {
source = "terraform-google-modules/lb-http/google//modules/frontend"
version = "~> 12.0"

project_id = var.project_id
name = "global-lb-fe-bucket"
url_map_input = module.lb-backend-iap.backend_service_info
}
19 changes: 19 additions & 0 deletions examples/backend-with-iap/outputs.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.
*/

output "load-balancer-ip" {
value = module.lb-frontend.external_ip
}
19 changes: 19 additions & 0 deletions examples/backend-with-iap/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
}
6 changes: 4 additions & 2 deletions examples/lb-http-separate-frontend-and-backend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ module "cloud-nat-group2" {
}

module "lb-http-backend" {
source = "terraform-google-modules/lb-http/google//modules/backend"
version = "~> 12.0"
source = "terraform-google-modules/lb-http/google//modules/backend"
version = "~> 12.0"

project_id = var.project_id
name = "backend-lb"
target_tags = [
Expand Down Expand Up @@ -105,6 +106,7 @@ module "lb-http-backend" {

iap_config = {
enable = false
iap_members = []
}
}

Expand Down
6 changes: 4 additions & 2 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ spec:
- name: serverless_negs
location: modules/serverless_negs
examples:
- name: backend-with-iap
location: examples/backend-with-iap
- name: cdn-policy
location: examples/cdn-policy
- name: certificate-map
Expand Down Expand Up @@ -336,13 +338,13 @@ spec:
roles:
- level: Project
roles:
- roles/storage.admin
- roles/compute.admin
- roles/run.admin
- roles/iam.serviceAccountUser
- roles/certificatemanager.owner
- roles/vpcaccess.admin
- roles/iam.serviceAccountAdmin
- roles/storage.admin
- roles/compute.admin
services:
- certificatemanager.googleapis.com
- cloudresourcemanager.googleapis.com
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This module creates `google_compute_backend_service` resource and its dependenci
| groups | The list of backend instance group which serves the traffic. | <pre>list(object({<br> group = string<br> description = optional(string)<br><br> balancing_mode = optional(string)<br> capacity_scaler = optional(number)<br> max_connections = optional(number)<br> max_connections_per_instance = optional(number)<br> max_connections_per_endpoint = optional(number)<br> max_rate = optional(number)<br> max_rate_per_instance = optional(number)<br> max_rate_per_endpoint = optional(number)<br> max_utilization = optional(number)<br> }))</pre> | `[]` | no |
| health\_check | Input for creating HttpHealthCheck or HttpsHealthCheck resource for health checking this BackendService. A health check must be specified unless the backend service uses an internet or serverless NEG as a backend. | <pre>object({<br> host = optional(string, null)<br> request_path = optional(string, null)<br> request = optional(string, null)<br> response = optional(string, null)<br> port = optional(number, null)<br> port_name = optional(string, null)<br> proxy_header = optional(string, null)<br> port_specification = optional(string, null)<br> protocol = optional(string, null)<br> check_interval_sec = optional(number, 5)<br> timeout_sec = optional(number, 5)<br> healthy_threshold = optional(number, 2)<br> unhealthy_threshold = optional(number, 2)<br> logging = optional(bool, false)<br> })</pre> | `null` | no |
| host\_path\_mappings | The list of host/path for which traffic could be sent to the backend service | <pre>list(object({<br> host = string<br> path = string<br> }))</pre> | <pre>[<br> {<br> "host": "*",<br> "path": "/*"<br> }<br>]</pre> | no |
| iap\_config | Settings for enabling Cloud Identity Aware Proxy Structure. | <pre>object({<br> enable = bool<br> oauth2_client_id = optional(string)<br> oauth2_client_secret = optional(string)<br> })</pre> | <pre>{<br> "enable": false<br>}</pre> | no |
| iap\_config | Settings for enabling Cloud Identity Aware Proxy and Users/SAs to be given IAP HttpResourceAccessor access to the service. | <pre>object({<br> enable = bool<br> oauth2_client_id = optional(string)<br> oauth2_client_secret = optional(string)<br> iap_members = list(string)<br> })</pre> | <pre>{<br> "enable": false,<br> "iap_members": []<br>}</pre> | no |
| load\_balancing\_scheme | Load balancing scheme type (EXTERNAL for classic external load balancer, EXTERNAL\_MANAGED for Envoy-based load balancer, INTERNAL\_MANAGED for internal load balancer and INTERNAL\_SELF\_MANAGED for traffic director) | `string` | `"EXTERNAL_MANAGED"` | no |
| locality\_lb\_policy | The load balancing algorithm used within the scope of the locality. | `string` | `null` | no |
| log\_config | This field denotes the logging options for the load balancer traffic served by this backend service. If logging is enabled, logs will be exported to Stackdriver. | <pre>object({<br> enable = bool<br> sample_rate = number<br> })</pre> | <pre>{<br> "enable": true,<br> "sample_rate": 1<br>}</pre> | no |
Expand Down
9 changes: 9 additions & 0 deletions modules/backend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,12 @@ resource "google_compute_backend_bucket" "default" {
}
}
}

resource "google_iap_web_backend_service_iam_member" "member" {
for_each = toset(var.iap_config.iap_members)
project = google_compute_backend_service.default[0].project
web_backend_service = google_compute_backend_service.default[0].name
role = "roles/iap.httpsResourceAccessor"
member = each.value
}

13 changes: 9 additions & 4 deletions modules/backend/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
description: {}
content:
examples:
- name: backend-with-iap
location: examples/backend-with-iap
- name: cdn-policy
location: examples/cdn-policy
- name: certificate-map
Expand Down Expand Up @@ -189,15 +191,17 @@ spec:
spec:
outputExpr: name
- name: iap_config
description: Settings for enabling Cloud Identity Aware Proxy Structure.
description: Settings for enabling Cloud Identity Aware Proxy and Users/SAs to be given IAP HttpResourceAccessor access to the service.
varType: |-
object({
enable = bool
oauth2_client_id = optional(string)
oauth2_client_secret = optional(string)
iap_members = list(string)
})
defaultValue:
enable: false
iap_members: []
- name: cdn_policy
description: Cloud CDN configuration for this BackendService.
varType: |-
Expand Down Expand Up @@ -331,16 +335,17 @@ spec:
roles:
- level: Project
roles:
- roles/iam.serviceAccountAdmin
- roles/compute.admin
- roles/storage.admin
- roles/run.admin
- roles/compute.networkAdmin
- roles/iap.admin
- roles/iam.serviceAccountUser
- roles/iam.serviceAccountAdmin
- roles/compute.admin
- roles/storage.admin
services:
- cloudresourcemanager.googleapis.com
- compute.googleapis.com
- iap.googleapis.com
- run.googleapis.com
- storage-api.googleapis.com
- vpcaccess.googleapis.com
Expand Down
5 changes: 3 additions & 2 deletions modules/backend/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ variable "backend_bucket_name" {
}

variable "iap_config" {
description = "Settings for enabling Cloud Identity Aware Proxy Structure."
description = "Settings for enabling Cloud Identity Aware Proxy and Users/SAs to be given IAP HttpResourceAccessor access to the service."
type = object({
enable = bool
oauth2_client_id = optional(string)
oauth2_client_secret = optional(string)
iap_members = list(string)
})
default = { enable = false }
default = { enable = false, iap_members = [] }
}

variable "cdn_policy" {
Expand Down
2 changes: 2 additions & 0 deletions modules/dynamic_backends/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
description: {}
content:
examples:
- name: backend-with-iap
location: examples/backend-with-iap
- name: cdn-policy
location: examples/cdn-policy
- name: certificate-map
Expand Down
4 changes: 3 additions & 1 deletion modules/frontend/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
description: {}
content:
examples:
- name: backend-with-iap
location: examples/backend-with-iap
- name: cdn-policy
location: examples/cdn-policy
- name: certificate-map
Expand Down Expand Up @@ -244,11 +246,11 @@ spec:
roles:
- level: Project
roles:
- roles/iam.serviceAccountUser
- roles/compute.admin
- roles/storage.admin
- roles/iap.admin
- roles/certificatemanager.owner
- roles/iam.serviceAccountUser
services:
- certificatemanager.googleapis.com
- compute.googleapis.com
Expand Down
6 changes: 4 additions & 2 deletions modules/serverless_negs/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
description: {}
content:
examples:
- name: backend-with-iap
location: examples/backend-with-iap
- name: cdn-policy
location: examples/cdn-policy
- name: certificate-map
Expand Down Expand Up @@ -292,13 +294,13 @@ spec:
roles:
- level: Project
roles:
- roles/vpcaccess.admin
- roles/iam.serviceAccountAdmin
- roles/storage.admin
- roles/compute.admin
- roles/run.admin
- roles/iam.serviceAccountUser
- roles/certificatemanager.owner
- roles/vpcaccess.admin
- roles/iam.serviceAccountAdmin
services:
- certificatemanager.googleapis.com
- cloudresourcemanager.googleapis.com
Expand Down
39 changes: 39 additions & 0 deletions test/integration/backend-with-iap/backend_with_iap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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.

package backend_with_iap

import (
"testing"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
"github.com/stretchr/testify/assert"

test "github.com/terraform-google-modules/terraform-google-lb-http/test/integration"
)

func TestExternalLbBackendBucket(t *testing.T) {
bpt := tft.NewTFBlueprintTest(t)

bpt.DefineVerify(func(assert *assert.Assertions) {
bpt.DefaultVerify(assert)

loadBalancerIp := bpt.GetStringOutput("load-balancer-ip")

test.AssertResponseStatus(t, assert, "http://"+loadBalancerIp, 200)
})

bpt.Test()
}

3 changes: 2 additions & 1 deletion test/setup/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ locals {
"roles/compute.networkAdmin",
"roles/iap.admin",
"roles/iam.serviceAccountUser",
"roles/iam.serviceAccountAdmin"
"roles/iam.serviceAccountAdmin",
"roles/iap.admin"
]
dynamic_backends = [
"roles/storage.admin",
Expand Down
1 change: 1 addition & 0 deletions test/setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ locals {
"storage-api.googleapis.com",
"vpcaccess.googleapis.com",
"cloudresourcemanager.googleapis.com",
"iap.googleapis.com",
]
dynamic_backends = [
"cloudresourcemanager.googleapis.com",
Expand Down