Use account regional namespace for access logs
This commit is contained in:
+4
-3
@@ -74,9 +74,10 @@ module "audit_logging_encryption" {
|
||||
name_prefix = var.name_prefix
|
||||
account_id = var.account_id
|
||||
|
||||
protect_from_destroy = true
|
||||
bucket_names = local.bucket_names
|
||||
access_log_bucket_name = "aws-s3-access-logs-${var.account_id}-${var.region}-an"
|
||||
protect_from_destroy = true
|
||||
bucket_names = local.bucket_names
|
||||
access_log_bucket_name = "aws-s3-access-logs-${var.account_id}-${var.region}-an"
|
||||
access_log_bucket_namespace = "account-regional"
|
||||
|
||||
trail_name = "management-events"
|
||||
kms_alias_name = "alias/vault-kms"
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user