Use account regional namespace for access logs

This commit is contained in:
2026-11-15 00:52:52 +09:00
parent 1f1888ecad
commit 7ec829fd0a
5 changed files with 31 additions and 7 deletions
@@ -53,6 +53,11 @@ run "apply_group1_osaka" {
error_message = "The Osaka test must create one unprotected, force-destroyable S3 access log bucket."
}
assert {
condition = aws_s3_bucket.access_logs_unprotected[0].bucket_namespace == "global"
error_message = "The Osaka test must keep the S3 access log bucket in the default global namespace."
}
assert {
condition = !aws_cloudtrail.management_events.is_multi_region_trail
error_message = "The Osaka test CloudTrail trail must be single-Region."
+6 -4
View File
@@ -103,8 +103,9 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
resource "aws_s3_bucket" "access_logs_protected" {
count = var.protect_from_destroy ? 1 : 0
bucket = local.access_log_bucket_name
force_destroy = false
bucket = local.access_log_bucket_name
bucket_namespace = var.access_log_bucket_namespace
force_destroy = false
lifecycle {
prevent_destroy = true
@@ -114,8 +115,9 @@ resource "aws_s3_bucket" "access_logs_protected" {
resource "aws_s3_bucket" "access_logs_unprotected" {
count = var.protect_from_destroy ? 0 : 1
bucket = local.access_log_bucket_name
force_destroy = var.force_destroy_unprotected_buckets
bucket = local.access_log_bucket_name
bucket_namespace = var.access_log_bucket_namespace
force_destroy = var.force_destroy_unprotected_buckets
}
resource "aws_s3_bucket_versioning" "access_logs" {
@@ -50,6 +50,11 @@ run "plan_group1_osaka" {
error_message = "The Osaka test must create one unprotected, force-destroyable S3 access log bucket."
}
assert {
condition = aws_s3_bucket.access_logs_unprotected[0].bucket_namespace == "global"
error_message = "The Osaka test must keep the S3 access log bucket in the default global namespace."
}
assert {
condition = !aws_cloudtrail.management_events.is_multi_region_trail
error_message = "The Osaka test CloudTrail trail must be single-Region."
@@ -40,6 +40,17 @@ variable "access_log_bucket_name" {
default = null
}
variable "access_log_bucket_namespace" {
description = "Namespace for the S3 server access log destination bucket. Isolated tests use the global namespace by default; production can opt in to account-regional."
type = string
default = "global"
validation {
condition = contains(["account-regional", "global"], var.access_log_bucket_namespace)
error_message = "access_log_bucket_namespace must be account-regional or global."
}
}
variable "trail_name" {
description = "CloudTrail trail name."
type = string