Sets up an S3 bucket with private access control list (ACL), ensuring that the bucket content is not publicly accessible.

Terraform Template

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

resource "aws_s3_bucket_acl" "example" {
  acl = "private"
  bucket = aws_s3_bucket.example.id
  depends_on = ["aws_s3_bucket_ownership_controls.example"]
}

resource "aws_s3_bucket_ownership_controls" "example" {
  bucket = aws_s3_bucket.example.id

  rule {
    object_ownership = "BucketOwnerPreferred"
  }
}