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

Enable S3 server access logging for media bucket #3129

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions deployment/terraform/modules/s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "aws_s3_bucket" "static_files" {
force_destroy = true
tags = "${var.tags}"

policy = <<EOF
policy = <<PUBLIC_ACCESS
{
"Version":"2012-10-17",
"Statement": [
Expand All @@ -19,7 +19,7 @@ resource "aws_s3_bucket" "static_files" {
}
]
}
EOF
PUBLIC_ACCESS

cors_rule {
allowed_headers = ["Authorization"]
Expand Down Expand Up @@ -57,7 +57,7 @@ resource "aws_s3_bucket" "media_files" {
bucket = "${var.bucket_name_base}-media"
tags = "${var.tags}"

policy = <<EOF
policy = <<PUBLIC_ACCESS
{
"Version":"2012-10-17",
"Statement": [
Expand All @@ -69,7 +69,7 @@ resource "aws_s3_bucket" "media_files" {
}
]
}
EOF
PUBLIC_ACCESS

versioning {
enabled = true
Expand All @@ -85,14 +85,20 @@ EOF
days = 14
}
}

logging {
target_bucket = "${aws_s3_bucket.log_files.id}"
# to match ELB log key name format
target_prefix = "AWSLogs/${data.aws_caller_identity.current.account_id}/s3/media/"
}
}

resource "aws_s3_bucket" "log_files" {
acl = "private"
acl = "log-delivery-write" # for S3 server access logging
bucket = "${var.bucket_name_base}-log"
tags = "${var.tags}"

policy = <<POLICY
policy = <<ELB_ACCESS_LOG
{
"Version": "2012-10-17",
"Statement": [
Expand All @@ -106,5 +112,5 @@ resource "aws_s3_bucket" "log_files" {
}
]
}
POLICY
ELB_ACCESS_LOG
}