From ed48258bdd3210b25c7129a92e32418e8d2f3b9b Mon Sep 17 00:00:00 2001 From: RB <7775707+nitrocode@users.noreply.github.com> Date: Thu, 14 Nov 2024 05:49:51 -0600 Subject: [PATCH] feat: add s3 request payment config (#259) * feat: add s3 request payment config var * fix: set optional key and add validation * feat: use s3 request payment config * fix: set default to BucketOwner * fix: validation for contains --------- Co-authored-by: Veronika Gnilitska <30597968+gberenice@users.noreply.github.com> --- main.tf | 8 ++++++++ variables.tf | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/main.tf b/main.tf index 2b7f281..9c46183 100644 --- a/main.tf +++ b/main.tf @@ -626,3 +626,11 @@ resource "aws_s3_directory_bucket" "default" { name = var.availability_zone_id } } + +resource "aws_s3_bucket_request_payment_configuration" "default" { + count = local.enabled && var.s3_request_payment_configuration.enabled ? 1 : 0 + + bucket = local.bucket_id + expected_bucket_owner = var.s3_request_payment_configuration.expected_bucket_owner + payer = lower(var.s3_request_payment_configuration.payer) == "requester" ? "Requester" : "BucketOwner" +} diff --git a/variables.tf b/variables.tf index 2b87e9a..c06ddde 100644 --- a/variables.tf +++ b/variables.tf @@ -494,6 +494,23 @@ variable "event_notification_details" { } } +variable "s3_request_payment_configuration" { + type = object({ + enabled = bool + expected_bucket_owner = optional(string) + payer = string + }) + description = "S3 request payment configuration" + default = { + enabled = false + payer = "BucketOwner" + } + validation { + condition = contains(["bucketowner", "requester"], lower(var.s3_request_payment_configuration.payer)) + error_message = "The s3 request payment config's payer must be either BucketOwner or Requester" + } +} + variable "create_s3_directory_bucket" { description = "Control the creation of the S3 directory bucket. Set to true to create the bucket, false to skip." type = bool