resource "aws_s3_bucket" "protected" { for_each = var.protect_from_destroy ? local.buckets : {} bucket = each.value force_destroy = false lifecycle { prevent_destroy = true } } resource "aws_s3_bucket" "unprotected" { for_each = var.protect_from_destroy ? {} : local.buckets bucket = each.value force_destroy = var.force_destroy_unprotected_buckets } resource "aws_s3_bucket_versioning" "this" { for_each = local.buckets bucket = local.bucket_ids[each.key] versioning_configuration { status = "Disabled" } } resource "aws_s3_bucket_server_side_encryption_configuration" "this" { for_each = local.buckets bucket = local.bucket_ids[each.key] rule { apply_server_side_encryption_by_default { sse_algorithm = "AES256" } bucket_key_enabled = each.key != "cloudtrail" blocked_encryption_types = ["SSE-C"] } } resource "aws_s3_bucket_public_access_block" "this" { for_each = local.buckets bucket = local.bucket_ids[each.key] block_public_acls = true block_public_policy = true ignore_public_acls = true restrict_public_buckets = true } resource "aws_s3_bucket_ownership_controls" "this" { for_each = local.buckets bucket = local.bucket_ids[each.key] rule { object_ownership = "BucketOwnerEnforced" } } resource "aws_s3_bucket_policy" "this" { for_each = local.buckets bucket = local.bucket_ids[each.key] policy = local.bucket_policies[each.key] } resource "aws_s3_bucket_lifecycle_configuration" "this" { for_each = local.lifecycle_rules bucket = local.bucket_ids[each.key] transition_default_minimum_object_size = "all_storage_classes_128K" rule { id = each.value.id status = "Enabled" expiration { days = each.value.expiration_days } } }