Skip to content

Commit 2e7c238

Browse files
authored
Add volumes support to Cron (#145)
Mostly copy/pasta from regional_go_service. Tested with my dev env. --------- Signed-off-by: Nghia Tran <[email protected]>
1 parent 0b0a748 commit 2e7c238

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

modules/cron/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ No modules.
101101
| <a name="input_secret_env"></a> [secret\_env](#input\_secret\_env) | A map of secrets to mount as environment variables from Google Secrets Manager (e.g. secret\_key=secret\_name) | `map` | `{}` | no |
102102
| <a name="input_service_account"></a> [service\_account](#input\_service\_account) | The email address of the service account to run the service as, and to invoke the job as. | `string` | n/a | yes |
103103
| <a name="input_timeout"></a> [timeout](#input\_timeout) | The maximum amount of time in seconds to allow the job to run. | `string` | `"600s"` | no |
104+
| <a name="input_volume_mounts"></a> [volume\_mounts](#input\_volume\_mounts) | The volume mounts to mount the volumes to the container in the job. | <pre>list(object({<br> name = string<br> mount_path = string<br> }))</pre> | `[]` | no |
105+
| <a name="input_volumes"></a> [volumes](#input\_volumes) | The volumes to make available to the container in the job for mounting. | <pre>list(object({<br> name = string<br> secret = optional(object({<br> secret = string<br> items = list(object({<br> version = string<br> path = string<br> }))<br> }))<br> }))</pre> | `[]` | no |
104106
| <a name="input_vpc_access"></a> [vpc\_access](#input\_vpc\_access) | The VPC to send egress to. For more information, visit https://cloud.google.com/run/docs/configuring/vpc-direct-vpc | <pre>object({<br> # Currently, only one network interface is supported.<br> network_interfaces = list(object({<br> network = string<br> subnetwork = string<br> tags = optional(list(string))<br> }))<br> # Egress is one of "PRIVATE_RANGES_ONLY", "ALL_TRAFFIC", or "ALL_PRIVATE_RANGES"<br> egress = string<br> })</pre> | `null` | no |
105107
| <a name="input_working_dir"></a> [working\_dir](#input\_working\_dir) | The working directory that contains the importpath. | `string` | n/a | yes |
106108

modules/cron/main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ resource "google_cloud_run_v2_job" "job" {
4646
service_account = var.service_account
4747
max_retries = var.max_retries
4848
timeout = var.timeout
49+
dynamic "volumes" {
50+
for_each = var.volumes
51+
content {
52+
name = volumes.value.name
53+
54+
dynamic "secret" {
55+
for_each = volumes.value.secret != null ? { "" : volumes.value.secret } : {}
56+
content {
57+
secret = secret.value.secret
58+
dynamic "items" {
59+
for_each = secret.value.items
60+
content {
61+
version = items.value.version
62+
path = items.value.path
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
4969
containers {
5070
image = ko_build.image.image_ref
5171

@@ -76,6 +96,14 @@ resource "google_cloud_run_v2_job" "job" {
7696
}
7797
}
7898
}
99+
100+
dynamic "volume_mounts" {
101+
for_each = var.volume_mounts
102+
content {
103+
name = volume_mounts.value.name
104+
mount_path = volume_mounts.value.mount_path
105+
}
106+
}
79107
}
80108

81109
dynamic "vpc_access" {

modules/cron/variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,27 @@ variable "vpc_access" {
9797
})
9898
description = "The VPC to send egress to. For more information, visit https://cloud.google.com/run/docs/configuring/vpc-direct-vpc"
9999
}
100+
101+
variable "volumes" {
102+
description = "The volumes to make available to the container in the job for mounting."
103+
type = list(object({
104+
name = string
105+
secret = optional(object({
106+
secret = string
107+
items = list(object({
108+
version = string
109+
path = string
110+
}))
111+
}))
112+
}))
113+
default = []
114+
}
115+
116+
variable "volume_mounts" {
117+
description = "The volume mounts to mount the volumes to the container in the job."
118+
type = list(object({
119+
name = string
120+
mount_path = string
121+
}))
122+
default = []
123+
}

0 commit comments

Comments
 (0)