Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional variable bucket_prefix for GCS object subdirectory path. #63

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) | `<map>` | 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 |
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down