Skip to content

Instantly share code, notes, and snippets.

@tarasowski
Last active February 25, 2025 08:42
Show Gist options
  • Save tarasowski/76250c9d6e5d5fc4acf828132758b58c to your computer and use it in GitHub Desktop.
Save tarasowski/76250c9d6e5d5fc4acf828132758b58c to your computer and use it in GitHub Desktop.
public bucket s3 terraform template
provider "aws" {
region = "us-east-1" # Change as needed
}
resource "aws_s3_bucket" "static_site" {
bucket = "my-static-site-bucket" # Change to a unique bucket name
}
resource "aws_s3_bucket_website_configuration" "static_site" {
bucket = aws_s3_bucket.static_site.id
index_document {
suffix = "index.html"
}
error_document {
key = "error.html"
}
}
resource "aws_s3_bucket_policy" "static_site_policy" {
bucket = aws_s3_bucket.static_site.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "${aws_s3_bucket.static_site.arn}/*"
}
]
}
POLICY
}
output "website_url" {
value = aws_s3_bucket_website_configuration.static_site.website_endpoint
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment