From 601f137c9b2b0edb22f26ff1efbc61688fad19ba Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Thu, 24 Oct 2024 08:36:20 +0200 Subject: [PATCH] Fix ipv6 output in net-vpc module, add support for extra volumes in cloud run v2 module (#2638) * fix #2637 * fix #2635 --- modules/cloud-run-v2/README.md | 2 +- modules/cloud-run-v2/job.tf | 15 +++++++++++++++ modules/cloud-run-v2/service.tf | 15 +++++++++++++++ modules/cloud-run-v2/variables.tf | 17 +++++++++++++++++ modules/net-vpc/outputs.tf | 2 +- 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/modules/cloud-run-v2/README.md b/modules/cloud-run-v2/README.md index a08978c5bb..e9fb7b61a8 100644 --- a/modules/cloud-run-v2/README.md +++ b/modules/cloud-run-v2/README.md @@ -499,7 +499,7 @@ module "cloud_run" { | [service_account](variables.tf#L221) | Service account email. Unused if service account is auto-created. | string | | null | | [service_account_create](variables.tf#L227) | Auto-create service account. | bool | | false | | [tag_bindings](variables.tf#L233) | Tag bindings for this service, in key => tag value id format. | map(string) | | {} | -| [volumes](variables.tf#L240) | Named volumes in containers in name => attributes format. | map(object({…})) | | {} | +| [volumes](variables.tf#L240) | Named volumes in containers in name => attributes format. | map(object({…})) | | {} | | [vpc_connector_create](variables-vpcconnector.tf#L17) | Populate this to create a Serverless VPC Access connector. | object({…}) | | null | ## Outputs diff --git a/modules/cloud-run-v2/job.tf b/modules/cloud-run-v2/job.tf index e42ae495ac..3b27df0f64 100644 --- a/modules/cloud-run-v2/job.tf +++ b/modules/cloud-run-v2/job.tf @@ -127,6 +127,21 @@ resource "google_cloud_run_v2_job" "job" { size_limit = volumes.value.empty_dir_size } } + dynamic "gcs" { + for_each = volumes.value.gcs == null ? [] : [""] + content { + bucket = volumes.value.bucket + read_only = volumes.value.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 + } + } } } } diff --git a/modules/cloud-run-v2/service.tf b/modules/cloud-run-v2/service.tf index 347068c652..fd69c71d13 100644 --- a/modules/cloud-run-v2/service.tf +++ b/modules/cloud-run-v2/service.tf @@ -205,6 +205,21 @@ resource "google_cloud_run_v2_service" "service" { size_limit = volumes.value.empty_dir_size } } + dynamic "gcs" { + for_each = volumes.value.gcs == null ? [] : [""] + content { + bucket = volumes.value.bucket + read_only = volumes.value.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 + } + } } } } diff --git a/modules/cloud-run-v2/variables.tf b/modules/cloud-run-v2/variables.tf index 459411b786..472b2f8e04 100644 --- a/modules/cloud-run-v2/variables.tf +++ b/modules/cloud-run-v2/variables.tf @@ -249,7 +249,24 @@ variable "volumes" { })) cloud_sql_instances = optional(list(string)) empty_dir_size = optional(string) + gcs = optional(object({ + # needs revision.gen2_execution_environment + bucket = string + is_read_only = optional(bool) + })) + nfs = optional(object({ + server = string + path = optional(string) + is_read_only = optional(bool) + })) })) default = {} nullable = false + validation { + condition = alltrue([ + for k, v in var.volumes : + sum([for kk, vv in v : vv == null ? 0 : 1]) == 1 + ]) + error_message = "Only one type of volume can be defined at a time." + } } diff --git a/modules/net-vpc/outputs.tf b/modules/net-vpc/outputs.tf index 4d143e829f..8184e96d44 100644 --- a/modules/net-vpc/outputs.tf +++ b/modules/net-vpc/outputs.tf @@ -28,7 +28,7 @@ output "id" { output "internal_ipv6_range" { description = "ULA range." - value = try(local.network.internal_ipv6_range, null) + value = try(google_compute_network.network[0].internal_ipv6_range, null) } output "name" {