Skip to content
Merged
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 |
| 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 |
| environment\_variables | A set of key/value environment variable pairs to assign to the function. | map(string) | `<map>` | no |
Expand Down
5 changes: 3 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ data "archive_file" "main" {
}

resource "google_storage_bucket" "main" {
count = var.create_bucket ? 1 : 0
name = coalesce(var.bucket_name, var.name)
force_destroy = var.bucket_force_destroy
location = var.region
Expand All @@ -59,7 +60,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)}"
bucket = google_storage_bucket.main.name
bucket = var.create_bucket ? google_storage_bucket.main[0].name : var.bucket_name
source = data.archive_file.main.output_path
content_disposition = "attachment"
content_encoding = "gzip"
Expand All @@ -85,7 +86,7 @@ resource "google_cloudfunctions_function" "main" {
labels = var.labels
runtime = var.runtime
environment_variables = var.environment_variables
source_archive_bucket = google_storage_bucket.main.name
source_archive_bucket = var.create_bucket ? google_storage_bucket.main[0].name : var.bucket_name
source_archive_object = google_storage_bucket_object.main.name
project = var.project_id
region = var.region
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ variable "bucket_name" {
description = "The name to apply to the bucket. Will default to a string of the function name."
}

variable "create_bucket" {
type = bool
default = true
description = "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."
}

variable "bucket_force_destroy" {
type = bool
default = false
Expand Down