From 4764b8f77ffcc8f0f97aaebb19a2235f31ffb013 Mon Sep 17 00:00:00 2001 From: Brigham Byerly <6891883+byerlyb20@users.noreply.github.com> Date: Fri, 24 Jan 2025 18:07:49 -0700 Subject: [PATCH 1/2] Added Content-Type for .wasm files --- s3.tf | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/s3.tf b/s3.tf index 426a960..84e1588 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,51 @@ resource "aws_s3_bucket_cors_configuration" "files" { } } -module "template_files" { - source = "hashicorp/dir/template" - - base_dir = var.dist_folder -} 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 } resource "aws_s3_object" "app_storage" { for_each = module.template_files.files @@ -80,4 +116,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 +} From 012e0c7475caed1bad048c6fc97fb05a83132dd6 Mon Sep 17 00:00:00 2001 From: Brigham Byerly <6891883+byerlyb20@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:19:25 -0700 Subject: [PATCH 2/2] Create robots.txt by default --- s3.tf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/s3.tf b/s3.tf index 426a960..c5251a4 100644 --- a/s3.tf +++ b/s3.tf @@ -55,10 +55,22 @@ resource "aws_s3_bucket_cors_configuration" "files" { } } +variable "create_robots_txt" { + type = bool + default = true +} + +resource "local_file" "robots-txt" { + count = var.create_robots_txt ? 1 : 0 + content = "User-agent: *\nDisallow: " + filename = "${var.dist_folder}/robots.txt" +} + module "template_files" { source = "hashicorp/dir/template" base_dir = var.dist_folder + depends_on = ["local_file.robots-txt"] } locals { content_type_overrides = {