Skip to content

Instantly share code, notes, and snippets.

@claydanford
Last active June 3, 2019 15:20
Show Gist options
  • Save claydanford/7e4304041b5d5233daf49daf2bde70cd to your computer and use it in GitHub Desktop.
Save claydanford/7e4304041b5d5233daf49daf2bde70cd to your computer and use it in GitHub Desktop.
S3 Static Website Example
resource "random_uuid" "name" {}
resource "aws_s3_bucket" "bucket" {
bucket = "${var.application}-${random_uuid.name.result}"
acl = "public-read"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${var.application}-${random_uuid.name.result}/*"
}
]
}
POLICY
website {
index_document = "index.html"
error_document = "404.html"
}
versioning {
enabled = false
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET", "HEAD"]
allowed_origins = ["*"]
max_age_seconds = 1800
}
tags = {
Name = "${var.application}-${random_uuid.name.result}"
Application = "${var.application}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment