From 6f1f6f50856bfa05de59b7435e43997ece588c4f Mon Sep 17 00:00:00 2001 From: Erin Horning Date: Mon, 21 Aug 2023 16:35:47 -0600 Subject: [PATCH] add additional parameters --- modules/gcs/README.md | 16 ++++++++-------- modules/gcs/main.tf | 28 ++++++++++++++++++++++++---- modules/gcs/variables.tf | 30 +++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/modules/gcs/README.md b/modules/gcs/README.md index 65e6beb98..7672f345b 100644 --- a/modules/gcs/README.md +++ b/modules/gcs/README.md @@ -114,7 +114,7 @@ module "bucket" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| | [name](variables.tf#L116) | Bucket name suffix. | string | ✓ | | -| [project_id](variables.tf#L155) | Bucket project id. | string | ✓ | | +| [project_id](variables.tf#L179) | Bucket project id. | string | ✓ | | | [cors](variables.tf#L17) | CORS configuration for the bucket. Defaults to null. | object({…}) | | null | | [encryption_key](variables.tf#L28) | KMS key that will be used for encryption. | string | | null | | [force_destroy](variables.tf#L34) | Optional map to set force destroy keyed by name, defaults to false. | bool | | false | @@ -124,13 +124,13 @@ module "bucket" { | [location](variables.tf#L101) | Bucket location. | string | | "EU" | | [logging_config](variables.tf#L107) | Bucket logging configuration. | object({…}) | | null | | [notification_config](variables.tf#L121) | GCS Notification configuration. | object({…}) | | null | -| [objects_to_upload](variables.tf#L135) | Objects to be uploaded to bucket | map(object({…})) | | {} | -| [prefix](variables.tf#L145) | Optional prefix used to generate the bucket name. | string | | null | -| [retention_policy](variables.tf#L160) | Bucket retention policy. | object({…}) | | null | -| [storage_class](variables.tf#L169) | Bucket storage class. | string | | "MULTI_REGIONAL" | -| [uniform_bucket_level_access](variables.tf#L179) | Allow using object ACLs (false) or not (true, this is the recommended behavior) , defaults to true (which is the recommended practice, but not the behavior of storage API). | bool | | true | -| [versioning](variables.tf#L185) | Enable versioning, defaults to false. | bool | | false | -| [website](variables.tf#L191) | Bucket website. | object({…}) | | null | +| [objects_to_upload](variables.tf#L135) | Objects to be uploaded to bucket. | map(object({…})) | | {} | +| [prefix](variables.tf#L169) | Optional prefix used to generate the bucket name. | string | | null | +| [retention_policy](variables.tf#L184) | Bucket retention policy. | object({…}) | | null | +| [storage_class](variables.tf#L193) | Bucket storage class. | string | | "MULTI_REGIONAL" | +| [uniform_bucket_level_access](variables.tf#L203) | Allow using object ACLs (false) or not (true, this is the recommended behavior) , defaults to true (which is the recommended practice, but not the behavior of storage API). | bool | | true | +| [versioning](variables.tf#L209) | Enable versioning, defaults to false. | bool | | false | +| [website](variables.tf#L215) | Bucket website. | object({…}) | | null | ## Outputs diff --git a/modules/gcs/main.tf b/modules/gcs/main.tf index ab3e6cb53..a0354febb 100644 --- a/modules/gcs/main.tf +++ b/modules/gcs/main.tf @@ -102,10 +102,30 @@ resource "google_storage_bucket" "bucket" { resource "google_storage_bucket_object" "objects" { for_each = var.objects_to_upload - bucket = google_storage_bucket.bucket.id - name = each.value.name - source = each.value.source - content_type = each.value.content_type + bucket = google_storage_bucket.bucket.id + name = each.value.name + metadata = each.value.metadata + content = each.value.content + source = each.value.source + cache_control = each.value.cache_control + content_disposition = each.value.content_disposition + content_encoding = each.value.content_encoding + content_language = each.value.content_language + content_type = each.value.content_type + event_based_hold = each.value.event_based_hold + temporary_hold = each.value.temporary_hold + detect_md5hash = each.value.detect_md5hash + storage_class = each.value.storage_class + kms_key_name = each.value.kms_key_name + + dynamic "customer_encryption" { + for_each = each.value.customer_encryption == null ? [] : [""] + + content { + encryption_algorithm = each.value.customer_encryption.encryption_algorithm + encryption_key = each.value.customer_encryption.encryption_key + } + } } resource "google_storage_bucket_iam_binding" "bindings" { diff --git a/modules/gcs/variables.tf b/modules/gcs/variables.tf index d425427fc..1077c0f04 100644 --- a/modules/gcs/variables.tf +++ b/modules/gcs/variables.tf @@ -135,10 +135,34 @@ variable "notification_config" { variable "objects_to_upload" { description = "Objects to be uploaded to bucket." type = map(object({ - name = string - source = string - content_type = string + name = string + metadata = optional(map(string)) + content = optional(string) + source = optional(string) + cache_control = optional(string) + content_disposition = optional(string) + content_encoding = optional(string) + content_language = optional(string) + content_type = optional(string) + event_based_hold = optional(bool) + temporary_hold = optional(bool) + detect_md5hash = optional(string) + storage_class = optional(string) + kms_key_name = optional(string) + customer_encryption = optional(object({ + encryption_algorithm = optional(string) + encryption_key = string + })) })) + validation { + condition = alltrue([ + for k, v in var.objects_to_upload : + v.content != null + || + v.source != null + ]) + error_message = "Object must have either content or source defined." + } default = {} }