Skip to content

Commit de668ba

Browse files
authored
fix(gcp/gcs-iap-proxy): some tweaks (#8)
* Make passing a bucket name optional, in case proxy image is nginx bundled with the SPA * Make sure latest revision is always serving 100% of the traffic * Make support email optional
1 parent b7e9a49 commit de668ba

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

modules/gcp/gcs-iap-proxy/main.tf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ resource "google_service_account" "proxy_sa" {
1717

1818
# Grant storage access to the service account
1919
resource "google_storage_bucket_iam_member" "proxy_storage_access" {
20+
count = var.bucket_name != "" ? 1 : 0
2021
bucket = var.bucket_name
2122
role = "roles/storage.objectViewer"
2223
member = "serviceAccount:${google_service_account.proxy_sa.email}"
@@ -36,9 +37,12 @@ resource "google_cloud_run_v2_service" "gcs_proxy" {
3637
image = var.proxy_image
3738

3839
# Core environment variables
39-
env {
40-
name = "GCS_BUCKET"
41-
value = var.bucket_name
40+
dynamic "env" {
41+
for_each = var.bucket_name != "" ? [1] : []
42+
content {
43+
name = "GCS_BUCKET"
44+
value = var.bucket_name
45+
}
4246
}
4347

4448
# SPA configuration
@@ -105,6 +109,11 @@ resource "google_cloud_run_v2_service" "gcs_proxy" {
105109
# Configure ingress to only allow load balancer traffic
106110
ingress = "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER"
107111

112+
traffic {
113+
type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"
114+
percent = 100
115+
}
116+
108117
labels = local.labels
109118

110119
depends_on = [

modules/gcp/gcs-iap-proxy/variables.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ variable "namespace" {
44
}
55

66
variable "bucket_name" {
7-
description = "The name of the GCS bucket to serve files from"
7+
description = "The name of the GCS bucket to serve files from (optional)"
88
type = string
9+
default = ""
910
}
1011

1112
variable "region" {
@@ -34,6 +35,7 @@ variable "iap_users" {
3435
variable "support_email" {
3536
description = "Support email for IAP OAuth consent screen"
3637
type = string
38+
default = ""
3739
}
3840

3941
variable "application_title" {

0 commit comments

Comments
 (0)