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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-13 18:27:29 +0000
Seen: 17 times
Last updated: May 13 '23
How can changes be disregarded in the lifecycle of Terraform?
What is the process for uploading files to Azure Storage using Terraform in Azure Pipeline?
How can two GCP instances with static IPs be created using Terraform?
How can ec2 instances be created in every availability zone using Terraform?
Does Terraform disregard values contained in .tfvars files?
How can one transform the source code of an Azure Data Factory into a Terraform script?