Skip to content
Merged
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
19 changes: 18 additions & 1 deletion terraform/website/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ resource "aws_s3_bucket" "logs" {
bucket = "${var.domain}-logs"
}

# Enable ACLs on the log bucket so CloudFront can write access logs
resource "aws_s3_bucket_ownership_controls" "logs" {
bucket = aws_s3_bucket.logs.id

rule {
object_ownership = "ObjectWriter"
}
}

resource "aws_s3_bucket_ownership_controls" "bucket" {
bucket = aws_s3_bucket.bucket.id
rule {
Expand All @@ -39,6 +48,14 @@ resource "aws_s3_bucket_acl" "bucket" {
acl = "public-read"
}

# Grant CloudFront permission to write access logs to this bucket
resource "aws_s3_bucket_acl" "logs" {
depends_on = [aws_s3_bucket_ownership_controls.logs]

bucket = aws_s3_bucket.logs.id
acl = "log-delivery-write"
}

# Configure website settings
resource "aws_s3_bucket_website_configuration" "bucket" {
bucket = aws_s3_bucket.bucket.id
Expand Down Expand Up @@ -83,7 +100,7 @@ resource "aws_cloudfront_distribution" "distribution" {

logging_config {
include_cookies = false
bucket = "${aws_s3_bucket.logs.bucket_regional_domain_name}"
bucket = aws_s3_bucket.logs.bucket_regional_domain_name
prefix = "cloudfront/"
}

Expand Down