Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ resource "aws_s3_bucket_website_configuration" "files" {
suffix = "index.html"
}
error_document {
key = "index.html"
# key = "error.html"
key = "index.html"
# key = "error.html"
}
}
resource "aws_s3_bucket_cors_configuration" "files" {
Expand All @@ -55,15 +55,63 @@ resource "aws_s3_bucket_cors_configuration" "files" {
}
}

module "template_files" {
source = "hashicorp/dir/template"
variable "create_robots_txt" {
type = bool
default = true
}

base_dir = var.dist_folder
resource "local_file" "robots-txt" {
count = var.create_robots_txt ? 1 : 0
content = "User-agent: *\nDisallow: "
filename = "${var.dist_folder}/robots.txt"
}

locals {
content_type_overrides = {
"apple-app-site-association" = "application/json"
}
# Taken from https://github.com/hashicorp/terraform-template-dir/blob/17b81de441645a94f4db1449fc8269cd32f26fde/variables.tf
# with some additions for file types we need to support
known_mime_types = {
".3g2" : "video/3gpp2",
".3gp" : "video/3gpp",
".atom" : "application/atom+xml",
".css" : "text/css; charset=utf-8",
".eot" : "application/vnd.ms-fontobject",
".gif" : "image/gif",
".htm" : "text/html; charset=utf-8",
".html" : "text/html; charset=utf-8",
".ico" : "image/vnd.microsoft.icon",
".jar" : "application/java-archive",
".jpeg" : "image/jpeg",
".jpg" : "image/jpeg",
".js" : "application/javascript",
".json" : "application/json",
".jsonld" : "application/ld+json",
".otf" : "font/otf",
".pdf" : "application/pdf",
".png" : "image/png",
".rss" : "application/rss+xml",
".svg" : "image/svg+xml",
".swf" : "application/x-shockwave-flash",
".ttf" : "font/ttf",
".txt" : "text/plain; charset=utf-8",
".weba" : "audio/webm",
".webm" : "video/webm",
".webp" : "image/webp",
".woff" : "font/woff",
".woff2" : "font/woff2",
".xhtml" : "application/xhtml+xml",
".xml" : "application/xml",
".wasm" : "application/wasm"
}
}
module "template_files" {
source = "hashicorp/dir/template"

base_dir = var.dist_folder
file_types = local.known_mime_types
depends_on = ["local_file.robots-txt"]
}
resource "aws_s3_object" "app_storage" {
for_each = module.template_files.files
Expand All @@ -80,4 +128,4 @@ resource "aws_s3_object" "app_storage" {
# Unless the bucket has encryption enabled, the ETag of each object is an
# MD5 hash of that object.
etag = each.value.digests.md5
}
}