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).
This commit is contained in:
Wiktor Niesiobędzki 2023-03-27 07:49:19 +00:00 committed by Wiktor Niesiobędzki
parent 987ea34d93
commit 082301c09c
3 changed files with 4 additions and 4 deletions

View File

@ -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. | <code>string</code> | ✓ | |
| [bundle_config](variables.tf#L37) | Cloud function source folder and generated zip bundle paths. Output path defaults to '/tmp/bundle.zip' if null. | <code title="object&#40;&#123;&#10; source_dir &#61; string&#10; output_path &#61; optional&#40;string, &#34;&#47;tmp&#47;bundle.zip&#34;&#41;&#10; excludes &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | ✓ | |
| [bundle_config](variables.tf#L37) | Cloud function source folder and generated zip bundle paths. Output path defaults to '/tmp/bundle.zip' if null. | <code title="object&#40;&#123;&#10; source_dir &#61; string&#10; output_path &#61; optional&#40;string&#41;&#10; excludes &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | ✓ | |
| [name](variables.tf#L94) | Name used for cloud function and associated resources. | <code>string</code> | ✓ | |
| [project_id](variables.tf#L109) | Project id used for all resources. | <code>string</code> | ✓ | |
| [bucket_config](variables.tf#L17) | Enable and configure auto-created bucket. Set fields to null to use defaults. | <code title="object&#40;&#123;&#10; location &#61; optional&#40;string&#41;&#10; lifecycle_delete_age_days &#61; optional&#40;number&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |

View File

@ -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
}

View File

@ -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))
})
}