Skip to content

Commit 1d470f1

Browse files
authored
feat: Add support for mounting gcs bucket in cloud run job (#326)
1 parent 9f0bd11 commit 1d470f1

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

modules/job-exec/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Functional examples are included in the
5454
| task\_count | Specifies the desired number of tasks the execution should run. | `number` | `null` | no |
5555
| timeout | Max allowed time duration the Task may be active before the system will actively try to mark it failed and kill associated containers. | `string` | `"600s"` | no |
5656
| volume\_mounts | Volume to mount into the container's filesystem. | <pre>list(object({<br> name = string<br> mount_path = string<br> }))</pre> | `[]` | no |
57-
| volumes | A list of Volumes to make available to containers. | <pre>list(object({<br> name = string<br> cloud_sql_instance = object({<br> instances = set(string)<br> })<br> }))</pre> | `[]` | no |
57+
| volumes | A list of Volumes to make available to containers. | <pre>list(object({<br> name = string<br> cloud_sql_instance = optional(object({<br> instances = set(string)<br> }))<br> gcs = optional(object({<br> bucket = string<br> read_only = optional(bool)<br> mount_options = optional(list(string))<br> }))<br> }))</pre> | `[]` | no |
5858
| vpc\_access | VPC Access configuration to use for this Task. | <pre>list(object({<br> connector = string<br> egress = string<br> }))</pre> | `[]` | no |
5959

6060
## Outputs

modules/job-exec/main.tf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,20 @@ resource "google_cloud_run_v2_job" "job" {
7979
for_each = var.volumes
8080
content {
8181
name = volumes.value["name"]
82-
cloud_sql_instance {
83-
instances = volumes.value.cloud_sql_instance["instances"]
82+
83+
dynamic "cloud_sql_instance" {
84+
for_each = volumes.value.cloud_sql_instance != null && try(volumes.value.cloud_sql_instance.instances, null) != null ? [volumes.value.cloud_sql_instance.instances] : []
85+
content {
86+
instances = try(volumes.value.cloud_sql_instance.instances, [])
87+
}
88+
}
89+
90+
dynamic "gcs" {
91+
for_each = volumes.value.gcs != null && try(volumes.value.gcs.bucket, null) != null ? [volumes.value.gcs.bucket] : []
92+
content {
93+
bucket = volumes.value.gcs.bucket
94+
read_only = volumes.value.gcs.read_only
95+
}
8496
}
8597
}
8698
}

modules/job-exec/variables.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ variable "task_count" {
114114
variable "volumes" {
115115
type = list(object({
116116
name = string
117-
cloud_sql_instance = object({
117+
cloud_sql_instance = optional(object({
118118
instances = set(string)
119-
})
119+
}))
120+
gcs = optional(object({
121+
bucket = string
122+
read_only = optional(bool)
123+
mount_options = optional(list(string))
124+
}))
120125
}))
121126
description = "A list of Volumes to make available to containers."
122127
default = []

0 commit comments

Comments
 (0)