From 082301c09c1e21fdcafe1e3f6b1191cdface1a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Niesiob=C4=99dzki?= Date: Mon, 27 Mar 2023 07:49:19 +0000 Subject: [PATCH] Use unique bundle name for Cloud Function When cloud-function module is used multiple times within project and default `bundle_config.output_path` is used then all the instances try to use filename and result is undefined without guarantee to converge to desired state (i.e. multiple functions may share the same code). --- modules/cloud-function/README.md | 2 +- modules/cloud-function/main.tf | 4 ++-- modules/cloud-function/variables.tf | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/cloud-function/README.md b/modules/cloud-function/README.md index ebf300fc..d6edb666 100644 --- a/modules/cloud-function/README.md +++ b/modules/cloud-function/README.md @@ -226,7 +226,7 @@ module "cf-http" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| | [bucket_name](variables.tf#L26) | Name of the bucket that will be used for the function code. It will be created with prefix prepended if bucket_config is not null. | string | ✓ | | -| [bundle_config](variables.tf#L37) | Cloud function source folder and generated zip bundle paths. Output path defaults to '/tmp/bundle.zip' if null. | object({…}) | ✓ | | +| [bundle_config](variables.tf#L37) | Cloud function source folder and generated zip bundle paths. Output path defaults to '/tmp/bundle.zip' if null. | object({…}) | ✓ | | | [name](variables.tf#L94) | Name used for cloud function and associated resources. | string | ✓ | | | [project_id](variables.tf#L109) | Project id used for all resources. | string | ✓ | | | [bucket_config](variables.tf#L17) | Enable and configure auto-created bucket. Set fields to null to use defaults. | object({…}) | | null | diff --git a/modules/cloud-function/main.tf b/modules/cloud-function/main.tf index 35dba729..70862234 100644 --- a/modules/cloud-function/main.tf +++ b/modules/cloud-function/main.tf @@ -267,8 +267,8 @@ resource "google_storage_bucket_object" "bundle" { data "archive_file" "bundle" { type = "zip" source_dir = var.bundle_config.source_dir - output_path = var.bundle_config.output_path - output_file_mode = "0666" + output_path = var.bundle_config.output_path != null ? var.bundle_config.output_path : "/tmp/bundle-${var.project_id}-${var.name}.zip" + output_file_mode = "0644" excludes = var.bundle_config.excludes } diff --git a/modules/cloud-function/variables.tf b/modules/cloud-function/variables.tf index 97a6217a..5f4b28c9 100644 --- a/modules/cloud-function/variables.tf +++ b/modules/cloud-function/variables.tf @@ -38,7 +38,7 @@ variable "bundle_config" { description = "Cloud function source folder and generated zip bundle paths. Output path defaults to '/tmp/bundle.zip' if null." type = object({ source_dir = string - output_path = optional(string, "/tmp/bundle.zip") + output_path = optional(string) excludes = optional(list(string)) }) }