diff --git a/README.md b/README.md index 84fb1d2..e4d37ff 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ module "localhost_function" { | files\_to\_exclude\_in\_source\_dir | Specify files to ignore when reading the source\_dir | `list(string)` | `[]` | no | | ingress\_settings | The ingress settings for the function. Allowed values are ALLOW\_ALL, ALLOW\_INTERNAL\_AND\_GCLB and ALLOW\_INTERNAL\_ONLY. Changes to this field will recreate the cloud function. | `string` | `"ALLOW_ALL"` | no | | labels | A set of key/value label pairs to assign to the Cloud Function. | `map(string)` | `{}` | no | +| log\_bucket | Log bucket | `string` | `null` | no | +| log\_object\_prefix | Log object prefix | `string` | `null` | no | | max\_instances | The maximum number of parallel executions of the function. | `number` | `0` | no | | name | The name to apply to any nameable resources. | `string` | n/a | yes | | project\_id | The ID of the project to which resources will be applied. | `string` | n/a | yes | diff --git a/main.tf b/main.tf index 4ffc649..08072b0 100644 --- a/main.tf +++ b/main.tf @@ -22,6 +22,16 @@ * is creating files. See this issue for more details * https://github.com/terraform-providers/terraform-provider-archive/issues/11 */ + +locals { + logging = var.log_bucket == null ? [] : [ + { + log_bucket = var.log_bucket + log_object_prefix = var.log_object_prefix + } + ] +} + resource "null_resource" "dependent_files" { triggers = { for file in var.source_dependent_files : @@ -57,6 +67,15 @@ resource "google_storage_bucket" "main" { storage_class = "REGIONAL" labels = var.bucket_labels uniform_bucket_level_access = true + + dynamic "logging" { + for_each = local.logging == [] ? [] : local.logging + content { + log_bucket = logging.value.log_bucket + log_object_prefix = logging.value.log_object_prefix + } + } + } resource "google_storage_bucket_object" "main" { diff --git a/variables.tf b/variables.tf index 473f65a..dac77fc 100644 --- a/variables.tf +++ b/variables.tf @@ -160,3 +160,16 @@ variable "vpc_connector" { default = null description = "The VPC Network Connector that this cloud function can connect to. It should be set up as fully-qualified URI. The format of this field is projects/*/locations/*/connectors/*." } + +variable "log_bucket" { + type = string + default = null + description = "Log bucket" +} + +variable "log_object_prefix" { + type = string + default = null + description = "Log object prefix" +} +