diff --git a/s3.tf b/s3.tf index 426a960..e632df2 100644 --- a/s3.tf +++ b/s3.tf @@ -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" { @@ -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 @@ -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 -} \ No newline at end of file +}