Last active
February 25, 2025 08:42
-
-
Save tarasowski/76250c9d6e5d5fc4acf828132758b58c to your computer and use it in GitHub Desktop.
public bucket s3 terraform template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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