From e97814a27d33594a445520fe5a36fec2622f5505 Mon Sep 17 00:00:00 2001 From: RB <7775707+nitrocode@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:39:07 -0600 Subject: [PATCH 1/5] feat: add s3 request payment config var --- variables.tf | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/variables.tf b/variables.tf index 3b9e732b..51a3caa8 100644 --- a/variables.tf +++ b/variables.tf @@ -493,6 +493,19 @@ variable "event_notification_details" { } } +variable "s3_request_payment_configuration" { + type = object({ + enabled = bool + bucket = string + expected_bucket_owner = string + payer = string + }) + description = "S3 request payment configuration" + default = { + enabled = false + } +} + 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 From ef80318ada4065fcc6e1c1ba01eb3957ffcbcb30 Mon Sep 17 00:00:00 2001 From: RB <7775707+nitrocode@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:53:17 -0600 Subject: [PATCH 2/5] fix: set optional key and add validation --- variables.tf | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index 51a3caa8..864558ac 100644 --- a/variables.tf +++ b/variables.tf @@ -496,14 +496,17 @@ variable "event_notification_details" { variable "s3_request_payment_configuration" { type = object({ enabled = bool - bucket = string - expected_bucket_owner = string + expected_bucket_owner = optional(string) payer = string }) description = "S3 request payment configuration" default = { enabled = false } + 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" { From 18c1742c289c994d616ca20a43d8700932f03874 Mon Sep 17 00:00:00 2001 From: RB <7775707+nitrocode@users.noreply.github.com> Date: Wed, 13 Nov 2024 23:01:04 -0600 Subject: [PATCH 3/5] feat: use s3 request payment config --- main.tf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.tf b/main.tf index 83993ff4..3831d014 100644 --- a/main.tf +++ b/main.tf @@ -623,3 +623,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" +} From 378d25d8ed74bb1ab19a3689c42724dd7a4249e3 Mon Sep 17 00:00:00 2001 From: RB <7775707+nitrocode@users.noreply.github.com> Date: Thu, 14 Nov 2024 00:09:32 -0600 Subject: [PATCH 4/5] fix: set default to BucketOwner --- variables.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/variables.tf b/variables.tf index 864558ac..162026e8 100644 --- a/variables.tf +++ b/variables.tf @@ -502,6 +502,7 @@ variable "s3_request_payment_configuration" { description = "S3 request payment configuration" default = { enabled = false + payer = "BucketOwner" } validation { condition = !contains(["bucketowner", "requester"], lower(var.s3_request_payment_configuration.payer)) From 1b08f19669db9b97b9c17f6a507c21fc541d11d3 Mon Sep 17 00:00:00 2001 From: RB <7775707+nitrocode@users.noreply.github.com> Date: Thu, 14 Nov 2024 01:52:40 -0600 Subject: [PATCH 5/5] fix: validation for contains --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 162026e8..2720e70a 100644 --- a/variables.tf +++ b/variables.tf @@ -505,7 +505,7 @@ variable "s3_request_payment_configuration" { payer = "BucketOwner" } validation { - condition = !contains(["bucketowner", "requester"], lower(var.s3_request_payment_configuration.payer)) + 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" } }