From 0177233943beadcd78f1ab2616aa390a2df48cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Niesiob=C4=99dzki?= Date: Thu, 14 Nov 2024 09:56:06 +0000 Subject: [PATCH] Fix gcs mounts for cloud-run-v2, closes #2684 --- modules/cloud-run-v2/README.md | 29 ++++++++++++++ modules/cloud-run-v2/service.tf | 12 +++--- .../cloud_run_v2/examples/gcs-mount.yaml | 40 +++++++++++++++++++ 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 tests/modules/cloud_run_v2/examples/gcs-mount.yaml diff --git a/modules/cloud-run-v2/README.md b/modules/cloud-run-v2/README.md index 7630c9438c..3628be99cb 100644 --- a/modules/cloud-run-v2/README.md +++ b/modules/cloud-run-v2/README.md @@ -5,6 +5,7 @@ Cloud Run Services and Jobs, with support for IAM roles and Eventarc trigger cre - [IAM and environment variables](#iam-and-environment-variables) - [Mounting secrets as volumes](#mounting-secrets-as-volumes) +- [Mounting GCS buckets](#mounting-gcs-buckets) - [Connecting to Cloud SQL database](#connecting-to-cloud-sql-database) - [Beta features](#beta-features) - [VPC Access Connector](#vpc-access-connector) @@ -84,6 +85,34 @@ module "cloud_run" { # tftest modules=2 resources=4 fixtures=fixtures/secret-credentials.tf inventory=service-volume-secretes.yaml e2e ``` +## Mounting GCS buckets + +```hcl +module "cloud_run" { + source = "./fabric/modules/cloud-run-v2" + project_id = var.project_id + name = "hello" + region = var.region + containers = { + hello = { + image = "us-docker.pkg.dev/cloudrun/container/hello" + volume_mounts = { + bucket = "/bucket" + } + } + } + volumes = { + bucket = { + gcs = { + bucket = var.bucket + is_read_only = false + } + } + } +} +# tftest inventory=gcs-mount.yaml e2e +``` + ## Connecting to Cloud SQL database ```hcl diff --git a/modules/cloud-run-v2/service.tf b/modules/cloud-run-v2/service.tf index fd69c71d13..0906f24a55 100644 --- a/modules/cloud-run-v2/service.tf +++ b/modules/cloud-run-v2/service.tf @@ -1,5 +1,5 @@ /** - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -208,16 +208,16 @@ resource "google_cloud_run_v2_service" "service" { dynamic "gcs" { for_each = volumes.value.gcs == null ? [] : [""] content { - bucket = volumes.value.bucket - read_only = volumes.value.is_read_only + bucket = volumes.value.gcs.bucket + read_only = volumes.value.gcs.is_read_only } } dynamic "nfs" { for_each = volumes.value.nfs == null ? [] : [""] content { - server = volumes.value.server - path = volumes.value.path - read_only = volumes.value.is_read_only + server = volumes.value.nfs.server + path = volumes.value.nfs.path + read_only = volumes.value.nfs.is_read_only } } } diff --git a/tests/modules/cloud_run_v2/examples/gcs-mount.yaml b/tests/modules/cloud_run_v2/examples/gcs-mount.yaml new file mode 100644 index 0000000000..59541b3297 --- /dev/null +++ b/tests/modules/cloud_run_v2/examples/gcs-mount.yaml @@ -0,0 +1,40 @@ +# Copyright 2024 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. + +values: + module.cloud_run.google_cloud_run_v2_service.service[0]: + location: europe-west8 + name: hello + project: project-id + template: + - containers: + - image: us-docker.pkg.dev/cloudrun/container/hello + name: hello + volume_mounts: + - mount_path: /bucket + name: bucket + execution_environment: EXECUTION_ENVIRONMENT_GEN1 + volumes: + - cloud_sql_instance: [] + empty_dir: [] + gcs: + - bucket: bucket + read_only: false + name: bucket + nfs: [] + secret: [] + +counts: + google_cloud_run_v2_service: 1 + modules: 1