1 | initial version |
To make an S3 Bucket accessible to the public using Terraform, you can add the following configuration to your Terraform code:
resource "aws_s3_bucket" "example_bucket" {
bucket = "example-bucket"
acl = "public-read"
}
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.