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

Allow external log bucket in different region #318

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 3 additions & 13 deletions bucket.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,16 @@
locals {
use_external_bucket = var.use_external_audit_log_bucket

audit_log_bucket_id = local.use_external_bucket ? data.aws_s3_bucket.external[0].id : module.audit_log_bucket[0].this_bucket.id
audit_log_bucket_arn = local.use_external_bucket ? data.aws_s3_bucket.external[0].arn : module.audit_log_bucket[0].this_bucket.arn
audit_log_bucket_id = local.use_external_bucket ? var.audit_log_bucket_id : module.audit_log_bucket[0].this_bucket.id
audit_log_bucket_arn = local.use_external_bucket ? var.audit_log_bucket_arn : module.audit_log_bucket[0].this_bucket.arn

audit_log_cloudtrail_destination = join("/", [local.audit_log_bucket_arn, trim(var.cloudtrail_s3_key_prefix, "/")])
audit_log_config_destination = join("/", [local.audit_log_bucket_arn, trim(var.config_s3_bucket_key_prefix, "/")])
audit_log_flow_logs_destination = join("/", [local.audit_log_bucket_arn, trim(var.vpc_flow_logs_s3_key_prefix, "/")])
}

# --------------------------------------------------------------------------------------------------
# Case 1. Use the external S3 bucket.
# --------------------------------------------------------------------------------------------------

data "aws_s3_bucket" "external" {
count = local.use_external_bucket ? 1 : 0

bucket = var.audit_log_bucket_name
}

# --------------------------------------------------------------------------------------------------
# Case 2. Create a new S3 bucket.
# If local.use_external_bucket = false, then create a bucket for audit logs
#
# Create a S3 bucket to store various audit logs.
# Bucket policies are derived from the default bucket policy and official AWS documents.
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ variable "use_external_audit_log_bucket" {
default = false
}

variable "audit_log_bucket_id" {
description = "The id of the S3 bucket to store various audit logs."
type = string
default = null
}

variable "audit_log_bucket_arn" {
description = "The arn of the S3 bucket to store various audit logs."
type = string
default = null
}

# --------------------------------------------------------------------------------------------------
# Variables for iam-baseline module.
# --------------------------------------------------------------------------------------------------
Expand Down