Skip to content

Commit 60cd78d

Browse files
authored
feat: add support for setting log bucket (#80)
* add parameter to log bucket * fmt * conditional to create block logging
1 parent f2b3a98 commit 60cd78d

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ module "localhost_function" {
6666
| files\_to\_exclude\_in\_source\_dir | Specify files to ignore when reading the source\_dir | `list(string)` | `[]` | no |
6767
| 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 |
6868
| labels | A set of key/value label pairs to assign to the Cloud Function. | `map(string)` | `{}` | no |
69+
| log\_bucket | Log bucket | `string` | `null` | no |
70+
| log\_object\_prefix | Log object prefix | `string` | `null` | no |
6971
| max\_instances | The maximum number of parallel executions of the function. | `number` | `0` | no |
7072
| name | The name to apply to any nameable resources. | `string` | n/a | yes |
7173
| project\_id | The ID of the project to which resources will be applied. | `string` | n/a | yes |

main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
* is creating files. See this issue for more details
2323
* https://github.com/terraform-providers/terraform-provider-archive/issues/11
2424
*/
25+
26+
locals {
27+
logging = var.log_bucket == null ? [] : [
28+
{
29+
log_bucket = var.log_bucket
30+
log_object_prefix = var.log_object_prefix
31+
}
32+
]
33+
}
34+
2535
resource "null_resource" "dependent_files" {
2636
triggers = {
2737
for file in var.source_dependent_files :
@@ -57,6 +67,15 @@ resource "google_storage_bucket" "main" {
5767
storage_class = "REGIONAL"
5868
labels = var.bucket_labels
5969
uniform_bucket_level_access = true
70+
71+
dynamic "logging" {
72+
for_each = local.logging == [] ? [] : local.logging
73+
content {
74+
log_bucket = logging.value.log_bucket
75+
log_object_prefix = logging.value.log_object_prefix
76+
}
77+
}
78+
6079
}
6180

6281
resource "google_storage_bucket_object" "main" {

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,16 @@ variable "vpc_connector" {
160160
default = null
161161
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/*."
162162
}
163+
164+
variable "log_bucket" {
165+
type = string
166+
default = null
167+
description = "Log bucket"
168+
}
169+
170+
variable "log_object_prefix" {
171+
type = string
172+
default = null
173+
description = "Log object prefix"
174+
}
175+

0 commit comments

Comments
 (0)