Skip to content

Commit

Permalink
Fix gcs mounts for cloud-run-v2, closes #2684
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktorn committed Nov 14, 2024
1 parent f1b074b commit 0177233
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
29 changes: 29 additions & 0 deletions modules/cloud-run-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Cloud Run Services and Jobs, with support for IAM roles and Eventarc trigger cre
<!-- BEGIN TOC -->
- [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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions modules/cloud-run-v2/service.tf
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions tests/modules/cloud_run_v2/examples/gcs-mount.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0177233

Please sign in to comment.