This template sets up an S3 bucket for storing files and a separate S3 bucket for logging access requests to the primary bucket.

Terraform Template

resource "aws_s3_bucket" "example" {
  bucket = "my-tf-example-bucket"
}

resource "aws_s3_bucket" "log_bucket" {
  bucket = "my-tf-log-bucket"
}

resource "aws_s3_bucket_acl" "example" {
  acl = "private"
  bucket = aws_s3_bucket.example.id
}

resource "aws_s3_bucket_acl" "log_bucket_acl" {
  acl = "log-delivery-write"
  bucket = aws_s3_bucket.log_bucket.id
}

resource "aws_s3_bucket_logging" "example" {
  bucket = aws_s3_bucket.example.id
  target_bucket = aws_s3_bucket.log_bucket.id
  target_prefix = "log/"
}