Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To make an S3 Bucket accessible to the public using Terraform, you can add the following configuration to your Terraform code:

  1. Add a bucket resource:
resource "aws_s3_bucket" "example_bucket" {
  bucket = "example-bucket"
  acl    = "public-read"
}

  1. Add a bucket policy:
resource "aws_s3_bucket_policy" "example_policy" {
  bucket = aws_s3_bucket.example_bucket.id

  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": [
        "s3:GetObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "${aws_s3_bucket.example_bucket.arn}",
        "${aws_s3_bucket.example_bucket.arn}/*"
      ]
    }
  ]
}
EOF
}

The above configuration will allow any user to read objects from and list the contents of the bucket. Note that making a bucket publicly accessible in this manner may present security risks, so you should review the possible consequences before implementing this approach.