Files
iD/terraform/main.tf
2025-06-12 17:05:34 -06:00

60 lines
1.3 KiB
HCL

provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "static_website" {
bucket = "editor.deflock.me"
tags = {
Name = "editor.deflock.me"
Environment = "Production"
}
}
resource "aws_s3_bucket_public_access_block" "static_website_public_access_block" {
bucket = aws_s3_bucket.static_website.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "null_resource" "sync_dist_to_s3" {
triggers = {
always_run = timestamp()
}
provisioner "local-exec" {
command = "aws s3 sync ../dist s3://${aws_s3_bucket.static_website.bucket}"
}
}
resource "aws_s3_bucket_policy" "static_website_policy" {
bucket = aws_s3_bucket.static_website.id
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Principal = "*",
Action = "s3:GetObject",
Resource = "${aws_s3_bucket.static_website.arn}/*"
}
]
})
}
resource "aws_s3_bucket_cors_configuration" "static_website_cors" {
bucket = aws_s3_bucket.static_website.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET"]
allowed_origins = ["editor.deflock.me"]
expose_headers = ["ETag"]
max_age_seconds = 3000
}
}