diff --git a/README.md b/README.md index 38e85c2..bf66993 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ module "localhost_function" { | bucket\_force\_destroy | When deleting the GCS bucket containing the cloud function, delete all objects in the bucket first. | bool | `"false"` | no | | bucket\_labels | A set of key/value label pairs to assign to the function source archive bucket. | map(string) | `` | no | | bucket\_name | The name to apply to the bucket. Will default to a string of the function name. | string | `""` | no | +| bucket\_prefix | The prefix of the bucket name for object subdirectory path. | string | `""` | no | | create\_bucket | Whether to create a new bucket or use an existing one. If false, `bucket_name` should reference the name of the alternate bucket to use. | bool | `"true"` | no | | description | The description of the function. | string | `"Processes events."` | no | | entry\_point | The name of a method in the function source which will be invoked when the function is executed. | string | n/a | yes | diff --git a/main.tf b/main.tf index c86a583..7c37f6e 100644 --- a/main.tf +++ b/main.tf @@ -59,7 +59,7 @@ resource "google_storage_bucket" "main" { } resource "google_storage_bucket_object" "main" { - name = "${data.archive_file.main.output_md5}-${basename(data.archive_file.main.output_path)}" + name = var.bucket_prefix != "" ? "${var.bucket_prefix}/${data.archive_file.main.output_md5}-${basename(data.archive_file.main.output_path)}" : "${data.archive_file.main.output_md5}-${basename(data.archive_file.main.output_path)}" bucket = var.create_bucket ? google_storage_bucket.main[0].name : var.bucket_name source = data.archive_file.main.output_path content_disposition = "attachment" diff --git a/variables.tf b/variables.tf index 5229486..294b659 100644 --- a/variables.tf +++ b/variables.tf @@ -112,6 +112,12 @@ variable "bucket_name" { description = "The name to apply to the bucket. Will default to a string of the function name." } +variable "bucket_prefix" { + type = string + default = "" + description = "The prefix of the bucket name for object subdirectory path." +} + variable "create_bucket" { type = bool default = true