From f38d8b24824b4add7c7b7468b3f5203dc1f52ae6 Mon Sep 17 00:00:00 2001 From: jjuinfare Date: Mon, 12 May 2025 17:47:32 +0200 Subject: [PATCH 1/2] lifecycle_transition_default_minimum_object_size --- README.md | 1 + docs/terraform.md | 1 + lifecycle.tf | 5 +++-- variables.tf | 13 +++++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 877de50f..824f8fbc 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,7 @@ Available targets: | [lifecycle\_configuration\_rules](#input\_lifecycle\_configuration\_rules) | A list of lifecycle V2 rules |
list(object({
enabled = optional(bool, true)
id = string

abort_incomplete_multipart_upload_days = optional(number)

# `filter_and` is the `and` configuration block inside the `filter` configuration.
# This is the only place you should specify a prefix.
filter_and = optional(object({
object_size_greater_than = optional(number) # integer >= 0
object_size_less_than = optional(number) # integer >= 1
prefix = optional(string)
tags = optional(map(string), {})
}))
expiration = optional(object({
date = optional(string) # string, RFC3339 time format, GMT
days = optional(number) # integer > 0
expired_object_delete_marker = optional(bool)
}))
noncurrent_version_expiration = optional(object({
newer_noncurrent_versions = optional(number) # integer > 0
noncurrent_days = optional(number) # integer >= 0
}))
transition = optional(list(object({
date = optional(string) # string, RFC3339 time format, GMT
days = optional(number) # integer > 0
storage_class = optional(string)
# string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
})), [])

noncurrent_version_transition = optional(list(object({
newer_noncurrent_versions = optional(number) # integer >= 0
noncurrent_days = optional(number) # integer >= 0
storage_class = optional(string)
# string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
})), [])
}))
| `[]` | no | | [lifecycle\_rule\_ids](#input\_lifecycle\_rule\_ids) | DEPRECATED (use `lifecycle_configuration_rules`): A list of IDs to assign to corresponding `lifecycle_rules` | `list(string)` | `[]` | no | | [lifecycle\_rules](#input\_lifecycle\_rules) | DEPRECATED (`use lifecycle_configuration_rules`): A list of lifecycle rules |
list(object({
prefix = string
enabled = bool
tags = map(string)

enable_glacier_transition = bool
enable_deeparchive_transition = bool
enable_standard_ia_transition = bool
enable_current_object_expiration = bool
enable_noncurrent_version_expiration = bool

abort_incomplete_multipart_upload_days = number
noncurrent_version_glacier_transition_days = number
noncurrent_version_deeparchive_transition_days = number
noncurrent_version_expiration_days = number

standard_transition_days = number
glacier_transition_days = number
deeparchive_transition_days = number
expiration_days = number
}))
| `null` | no | +| [lifecycle\_transition\_default\_minimum\_object\_size](#input\_lifecycle\_transition\_default\_minimum\_object\_size) | Specifies the default minimum object size behavior applied to the lifecycle configuration.
Valid values are `all_storage_classes_128K`(default) and `varies_by_storage_class`. | `string` | `"all_storage_classes_128K"` | no | | [logging](#input\_logging) | Bucket access logging configuration. Empty list for no logging, list of 1 to enable logging. |
list(object({
bucket_name = string
prefix = string
}))
| `[]` | no | | [minimum\_tls\_version](#input\_minimum\_tls\_version) | Set the minimum TLS version for in-transit traffic | `string` | `null` | no | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 8cd1f63b..52ca1555 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -91,6 +91,7 @@ | [lifecycle\_configuration\_rules](#input\_lifecycle\_configuration\_rules) | A list of lifecycle V2 rules |
list(object({
enabled = optional(bool, true)
id = string

abort_incomplete_multipart_upload_days = optional(number)

# `filter_and` is the `and` configuration block inside the `filter` configuration.
# This is the only place you should specify a prefix.
filter_and = optional(object({
object_size_greater_than = optional(number) # integer >= 0
object_size_less_than = optional(number) # integer >= 1
prefix = optional(string)
tags = optional(map(string), {})
}))
expiration = optional(object({
date = optional(string) # string, RFC3339 time format, GMT
days = optional(number) # integer > 0
expired_object_delete_marker = optional(bool)
}))
noncurrent_version_expiration = optional(object({
newer_noncurrent_versions = optional(number) # integer > 0
noncurrent_days = optional(number) # integer >= 0
}))
transition = optional(list(object({
date = optional(string) # string, RFC3339 time format, GMT
days = optional(number) # integer > 0
storage_class = optional(string)
# string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
})), [])

noncurrent_version_transition = optional(list(object({
newer_noncurrent_versions = optional(number) # integer >= 0
noncurrent_days = optional(number) # integer >= 0
storage_class = optional(string)
# string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
})), [])
}))
| `[]` | no | | [lifecycle\_rule\_ids](#input\_lifecycle\_rule\_ids) | DEPRECATED (use `lifecycle_configuration_rules`): A list of IDs to assign to corresponding `lifecycle_rules` | `list(string)` | `[]` | no | | [lifecycle\_rules](#input\_lifecycle\_rules) | DEPRECATED (`use lifecycle_configuration_rules`): A list of lifecycle rules |
list(object({
prefix = string
enabled = bool
tags = map(string)

enable_glacier_transition = bool
enable_deeparchive_transition = bool
enable_standard_ia_transition = bool
enable_current_object_expiration = bool
enable_noncurrent_version_expiration = bool

abort_incomplete_multipart_upload_days = number
noncurrent_version_glacier_transition_days = number
noncurrent_version_deeparchive_transition_days = number
noncurrent_version_expiration_days = number

standard_transition_days = number
glacier_transition_days = number
deeparchive_transition_days = number
expiration_days = number
}))
| `null` | no | +| [lifecycle\_transition\_default\_minimum\_object\_size](#input\_lifecycle\_transition\_default\_minimum\_object\_size) | Specifies the default minimum object size behavior applied to the lifecycle configuration.
Valid values are `all_storage_classes_128K`(default) and `varies_by_storage_class`. | `string` | `"all_storage_classes_128K"` | no | | [logging](#input\_logging) | Bucket access logging configuration. Empty list for no logging, list of 1 to enable logging. |
list(object({
bucket_name = string
prefix = string
}))
| `[]` | no | | [minimum\_tls\_version](#input\_minimum\_tls\_version) | Set the minimum TLS version for in-transit traffic | `string` | `null` | no | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | diff --git a/lifecycle.tf b/lifecycle.tf index 90918fc3..72378851 100644 --- a/lifecycle.tf +++ b/lifecycle.tf @@ -157,8 +157,9 @@ locals { resource "aws_s3_bucket_lifecycle_configuration" "default" { - count = local.enabled && length(local.lc_rules) > 0 ? 1 : 0 - bucket = local.bucket_id + count = local.enabled && length(local.lc_rules) > 0 ? 1 : 0 + bucket = local.bucket_id + transition_default_minimum_object_size = var.lifecycle_transition_default_minimum_object_size dynamic "rule" { for_each = local.lc_rules diff --git a/variables.tf b/variables.tf index e8d41715..c3f9251f 100644 --- a/variables.tf +++ b/variables.tf @@ -189,6 +189,19 @@ variable "lifecycle_configuration_rules" { } # See lifecycle.tf for conversion of deprecated `lifecycle_rules` to `lifecycle_configuration_rules` +variable "lifecycle_transition_default_minimum_object_size" { + type = string + default = "all_storage_classes_128K" + description = <<-EOT + Specifies the default minimum object size behavior applied to the lifecycle configuration. + Valid values are `all_storage_classes_128K`(default) and `varies_by_storage_class`. + EOT + validation { + condition = contains(["all_storage_classes_128K", "varies_by_storage_class"], lower(var.lifecycle_transition_default_minimum_object_size)) + error_message = "The s3 request payment config's payer must be either BucketOwner or Requester" + } + nullable = false +} variable "cors_configuration" { type = list(object({ From f27020e5b0572dbfdb7d3f3239f68e8b316ad564 Mon Sep 17 00:00:00 2001 From: jjuinfare Date: Mon, 12 May 2025 17:59:29 +0200 Subject: [PATCH 2/2] Fix validation --- variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index c3f9251f..93162b5a 100644 --- a/variables.tf +++ b/variables.tf @@ -197,8 +197,8 @@ variable "lifecycle_transition_default_minimum_object_size" { Valid values are `all_storage_classes_128K`(default) and `varies_by_storage_class`. EOT validation { - condition = contains(["all_storage_classes_128K", "varies_by_storage_class"], lower(var.lifecycle_transition_default_minimum_object_size)) - error_message = "The s3 request payment config's payer must be either BucketOwner or Requester" + condition = contains(["all_storage_classes_128K", "varies_by_storage_class"], var.lifecycle_transition_default_minimum_object_size) + error_message = "The default minimum object size for transitions must be either all_storage_classes_128K or varies_by_storage_class" } nullable = false }