Skip to content

Commit

Permalink
feat: Add support for log bucket configuration (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
matty-rose committed Jun 3, 2021
1 parent acaf67f commit eca9c57
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -62,6 +62,7 @@ Functional examples are included in the
| labels | Labels to be attached to the buckets | `map(string)` | `{}` | no |
| lifecycle\_rules | List of lifecycle rules to configure. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#lifecycle_rule except condition.matches\_storage\_class should be a comma delimited string. | <pre>set(object({<br> # Object with keys:<br> # - type - The type of the action of this Lifecycle Rule. Supported values: Delete and SetStorageClass.<br> # - storage_class - (Required if action type is SetStorageClass) The target Storage Class of objects affected by this Lifecycle Rule.<br> action = map(string)<br><br> # Object with keys:<br> # - age - (Optional) Minimum age of an object in days to satisfy this condition.<br> # - created_before - (Optional) Creation date of an object in RFC 3339 (e.g. 2017-06-13) to satisfy this condition.<br> # - with_state - (Optional) Match to live and/or archived objects. Supported values include: "LIVE", "ARCHIVED", "ANY".<br> # - matches_storage_class - (Optional) Comma delimited string for storage class of objects to satisfy this condition. Supported values include: MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, STANDARD, DURABLE_REDUCED_AVAILABILITY.<br> # - num_newer_versions - (Optional) Relevant only for versioned objects. The number of newer versions of an object to satisfy this condition.<br> condition = map(string)<br> }))</pre> | `[]` | no |
| location | Bucket location. | `string` | `"EU"` | no |
| logging | Map of lowercase unprefixed name => bucket logging config object. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#logging | `any` | `{}` | no |
| names | Bucket name suffixes. | `list(string)` | n/a | yes |
| prefix | Prefix used to generate the bucket name. | `string` | n/a | yes |
| project\_id | Bucket project id. | `string` | n/a | yes |
Expand Down
7 changes: 7 additions & 0 deletions main.tf
Expand Up @@ -105,6 +105,13 @@ resource "google_storage_bucket" "buckets" {
}
}

dynamic "logging" {
for_each = lookup(var.logging, each.value, {}) != {} ? { v = lookup(var.logging, each.value) } : {}
content {
log_bucket = lookup(logging.value, "log_bucket", null)
log_object_prefix = lookup(logging.value, "log_object_prefix", null)
}
}
}

resource "google_storage_bucket_iam_binding" "admins" {
Expand Down
2 changes: 2 additions & 0 deletions modules/simple_bucket/README.md
Expand Up @@ -45,6 +45,8 @@ Functional examples are included in the
| labels | A set of key/value label pairs to assign to the bucket. | `map(string)` | `null` | no |
| lifecycle\_rules | The bucket's Lifecycle Rules configuration. | <pre>list(object({<br> # Object with keys:<br> # - type - The type of the action of this Lifecycle Rule. Supported values: Delete and SetStorageClass.<br> # - storage_class - (Required if action type is SetStorageClass) The target Storage Class of objects affected by this Lifecycle Rule.<br> action = any<br><br> # Object with keys:<br> # - age - (Optional) Minimum age of an object in days to satisfy this condition.<br> # - created_before - (Optional) Creation date of an object in RFC 3339 (e.g. 2017-06-13) to satisfy this condition.<br> # - with_state - (Optional) Match to live and/or archived objects. Supported values include: "LIVE", "ARCHIVED", "ANY".<br> # - matches_storage_class - (Optional) Storage Class of objects to satisfy this condition. Supported values include: MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, STANDARD, DURABLE_REDUCED_AVAILABILITY.<br> # - num_newer_versions - (Optional) Relevant only for versioned objects. The number of newer versions of an object to satisfy this condition.<br> condition = any<br> }))</pre> | `[]` | no |
| location | The location of the bucket. | `string` | n/a | yes |
| log\_bucket | The bucket that will receive log objects. | `string` | `null` | no |
| log\_object\_prefix | The object prefix for log objects. If it's not provided, by default GCS sets this to this bucket's name | `string` | `null` | no |
| name | The name of the bucket. | `string` | n/a | yes |
| project\_id | The ID of the project to create the bucket in. | `string` | n/a | yes |
| retention\_policy | Configuration of the bucket's data retention policy for how long objects in the bucket should be retained. | <pre>object({<br> is_locked = bool<br> retention_period = number<br> })</pre> | `null` | no |
Expand Down
8 changes: 8 additions & 0 deletions modules/simple_bucket/main.tf
Expand Up @@ -58,6 +58,14 @@ resource "google_storage_bucket" "bucket" {
}
}
}

dynamic "logging" {
for_each = var.log_bucket == null ? [] : [var.log_bucket]
content {
log_bucket = var.log_bucket
log_object_prefix = var.log_object_prefix
}
}
}

resource "google_storage_bucket_iam_member" "members" {
Expand Down
12 changes: 12 additions & 0 deletions modules/simple_bucket/variables.tf
Expand Up @@ -104,3 +104,15 @@ variable "lifecycle_rules" {
}))
default = []
}

variable "log_bucket" {
description = "The bucket that will receive log objects."
type = string
default = null
}

variable "log_object_prefix" {
description = "The object prefix for log objects. If it's not provided, by default GCS sets this to this bucket's name"
type = string
default = null
}
6 changes: 6 additions & 0 deletions variables.tf
Expand Up @@ -199,3 +199,9 @@ variable "website" {
default = {}
description = "Map of website values. Supported attributes: main_page_suffix, not_found_page"
}

variable "logging" {
description = "Map of lowercase unprefixed name => bucket logging config object. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#logging"
type = any
default = {}
}

0 comments on commit eca9c57

Please sign in to comment.