Skip to content

Commit

Permalink
add access logs bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
dudizimber committed Nov 7, 2024
1 parent d755f69 commit 0335aa4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
49 changes: 36 additions & 13 deletions tofu/aws/3-application_plane/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ locals {
}),
{}
)
app_plane_account = local.workload_accounts[var.app_plane_account_name]
app_plane_trail_bucket_name = nonsensitive("${lower(replace(var.app_plane_account_name, " ", "-"))}-cloudtrail-${random_bytes.suffix.hex}")
app_plane_account = local.workload_accounts[var.app_plane_account_name]
app_plane_trail_bucket_name = nonsensitive("${lower(replace(var.app_plane_account_name, " ", "-"))}-cloudtrail-${random_bytes.suffix.hex}")
app_plane_access_logs_bucket_name = nonsensitive("${lower(replace(var.app_plane_account_name, " ", "-"))}-access-logs-${random_bytes.suffix.hex}")
}

Expand Down Expand Up @@ -69,29 +69,52 @@ module "aws-s3-bucket" {
}
}

data "aws_iam_policy_document" "access_logs_bucket_policy" {

statement {
effect = "Allow"
actions = ["s3:GetBucketAcl"]
resources = ["arn:aws:s3:::${local.app_plane_access_logs_bucket_name}"]
principals {
type = "Service"
identifiers = ["delivery.logs.amazonaws.com"]
}
}

statement {
effect = "Allow"
actions = ["s3:PutObject"]
resources = ["arn:aws:s3:::${local.app_plane_access_logs_bucket_name}/*"]
principals {
type = "Service"
identifiers = ["delivery.logs.amazonaws.com"]
}
}
}

module "aws-s3-bucket-access-logs" {
source = "trussworks/s3-private-bucket/aws"
bucket = local.app_plane_access_logs_bucket_name
use_account_alias_prefix = false
enable_analytics = false

custom_bucket_policy = data.aws_iam_policy_document.cloudtrail_bucket_policy.json
custom_bucket_policy = data.aws_iam_policy_document.access_logs_bucket_policy.json

providers = {
aws = aws.app-plane-account
}
}

module "cloudtrail" {
source = "trussworks/cloudtrail/aws"
version = "5.2.0"
# module "cloudtrail" {
# source = "trussworks/cloudtrail/aws"
# version = "5.2.0"

s3_bucket_name = module.aws-s3-bucket.id
log_retention_days = var.cloudtrail_retention_days
# s3_bucket_name = module.aws-s3-bucket.id
# log_retention_days = var.cloudtrail_retention_days

providers = {
aws = aws.app-plane-account
}
# providers = {
# aws = aws.app-plane-account
# }

depends_on = [module.aws-s3-bucket, data.aws_iam_policy_document.cloudtrail_bucket_policy]
}
# depends_on = [module.aws-s3-bucket, data.aws_iam_policy_document.cloudtrail_bucket_policy]
# }
8 changes: 7 additions & 1 deletion tofu/aws/3-application_plane/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ variable "cloudtrail_retention_days" {
type = number
description = "Number of days to retain CloudTrail logs"
default = 90
}
}

variable "app_plane_lb_bucket_access_allow_list" {
type = list(string)
description = "List of ARNs of load balancers that are allowed to write to the access logs bucket"
default = []
}

0 comments on commit 0335aa4

Please sign in to comment.