Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge S3 lifecycle configuration into one object #294

Merged
merged 6 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [7.9.3] - 2025-02-25
### Fixed
- Merged all S3 lifecycle configurations into `aws_s3_bucket_lifecycle_configuration` object.

## [7.9.2] - 2025-02-24
### Fixed
- Fix gluesync on k8s deployment
Expand Down
44 changes: 21 additions & 23 deletions s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,12 @@ resource "aws_s3_bucket" "apiary_data_bucket" {
target_bucket = local.enable_apiary_s3_log_management ? aws_s3_bucket.apiary_managed_logs_bucket[0].id : var.apiary_log_bucket
target_prefix = "${var.apiary_log_prefix}${each.value["data_bucket"]}/"
}

lifecycle_rule {
id = "cost_optimization"
enabled = true

abort_incomplete_multipart_upload_days = var.s3_lifecycle_abort_incomplete_multipart_upload_days

dynamic "transition" {
for_each = each.value["s3_object_expiration_days_num"] == "-1" || each.value["s3_lifecycle_policy_transition_period"] < each.value["s3_object_expiration_days_num"] ? [1] : []
content {
days = each.value["s3_lifecycle_policy_transition_period"]
storage_class = each.value["s3_storage_class"]
}
}

dynamic "expiration" {
for_each = each.value["s3_object_expiration_days_num"] != "-1" ? [1] : []
content {
days = each.value["s3_object_expiration_days_num"]
}
}
}
}

resource "aws_s3_bucket_versioning" "apiary_data_bucket_versioning" {
for_each = {
for schema in local.schemas_info : "${schema["schema_name"]}" => schema
if lookup(schema, "s3_versioning_enabled", "") != ""
}
bucket = each.value["data_bucket"]
versioning_configuration {
Expand All @@ -89,7 +68,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "apiary_data_bucket_versioning_
for schema in local.schemas_info : "${schema["schema_name"]}" => schema
}
bucket = each.value["data_bucket"]
# Rule enabled when expiration max days is set
# Rule for s3 versioning expiration
rule {
id = "expire-noncurrent-versions-days"
status = lookup(each.value, "s3_versioning_enabled", "") != "" ? "Enabled" : "Disabled"
Expand All @@ -98,6 +77,25 @@ resource "aws_s3_bucket_lifecycle_configuration" "apiary_data_bucket_versioning_
noncurrent_days = tonumber(lookup(each.value, "s3_versioning_expiration_days", var.s3_versioning_expiration_days))
}
}
# Rule s3 intelligent tiering transition
rule {
id = "cost_optimization_transition"
status = each.value["s3_object_expiration_days_num"] == "-1" || each.value["s3_lifecycle_policy_transition_period"] < each.value["s3_object_expiration_days_num"] ? "Enabled" : "Disabled"

transition {
days = each.value["s3_lifecycle_policy_transition_period"]
storage_class = each.value["s3_storage_class"]
}
}
# Rule s3 object expiration
rule {
id = "cost_optimization_expiration"
status = each.value["s3_object_expiration_days_num"] != "-1" ? "Enabled" : "Disabled"

expiration {
days = each.value["s3_object_expiration_days_num"]
}
}
}

resource "aws_s3_bucket_inventory" "apiary_bucket" {
Expand Down
Loading