Creates an S3 bucket with custom grants, specifying access permissions for different users and groups.

Terraform Template

data "aws_canonical_user_id" "current" {
}

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

resource "aws_s3_bucket_acl" "example" {

  access_control_policy {

    grant {

      grantee {
        id = data.aws_canonical_user_id.current.id
        type = "CanonicalUser"
      }
      permission = "READ"
    }

    grant {

      grantee {
        type = "Group"
        uri = "http://acs.amazonaws.com/groups/s3/LogDelivery"
      }
      permission = "READ_ACP"
    }

    owner {
      id = data.aws_canonical_user_id.current.id
    }
  }
  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"
  }
}