@@ -55,42 +55,58 @@ resource "aws_s3_bucket_cors_configuration" "files" {
5555 }
5656}
5757
58+ variable "create_robots_txt" {
59+ type = bool
60+ default = true
61+ }
62+
63+ resource "local_file" "robots-txt" {
64+ count = var. create_robots_txt ? 1 : 0
65+ content = " User-agent: *\n Disallow: "
66+ filename = " ${ var . dist_folder } /robots.txt"
67+ }
68+
69+ module "template_files" {
70+ source = " hashicorp/dir/template"
71+
72+ base_dir = var. dist_folder
73+ }
5874locals {
5975 content_type_overrides = {
6076 " apple-app-site-association" = " application/json"
6177 }
6278 # Taken from https://github.com/hashicorp/terraform-template-dir/blob/17b81de441645a94f4db1449fc8269cd32f26fde/variables.tf
6379 # with some additions for file types we need to support
6480 known_mime_types = {
65- " .3g2" : " video/3gpp2" ,
66- " .3gp" : " video/3gpp" ,
67- " .atom" : " application/atom+xml" ,
68- " .css" : " text/css; charset=utf-8" ,
69- " .eot" : " application/vnd.ms-fontobject" ,
70- " .gif" : " image/gif" ,
71- " .htm" : " text/html; charset=utf-8" ,
72- " .html" : " text/html; charset=utf-8" ,
73- " .ico" : " image/vnd.microsoft.icon" ,
74- " .jar" : " application/java-archive" ,
75- " .jpeg" : " image/jpeg" ,
76- " .jpg" : " image/jpeg" ,
77- " .js" : " application/javascript" ,
78- " .json" : " application/json" ,
79- " .jsonld" : " application/ld+json" ,
80- " .otf" : " font/otf" ,
81- " .pdf" : " application/pdf" ,
82- " .png" : " image/png" ,
83- " .rss" : " application/rss+xml" ,
84- " .svg" : " image/svg+xml" ,
85- " .swf" : " application/x-shockwave-flash" ,
86- " .ttf" : " font/ttf" ,
87- " .txt" : " text/plain; charset=utf-8" ,
88- " .weba" : " audio/webm" ,
89- " .webm" : " video/webm" ,
90- " .webp" : " image/webp" ,
91- " .woff" : " font/woff" ,
92- " .woff2" : " font/woff2" ,
93- " .xhtml" : " application/xhtml+xml" ,
81+ " .3g2" : " video/3gpp2" ,
82+ " .3gp" : " video/3gpp" ,
83+ " .atom" : " application/atom+xml" ,
84+ " .css" : " text/css; charset=utf-8" ,
85+ " .eot" : " application/vnd.ms-fontobject" ,
86+ " .gif" : " image/gif" ,
87+ " .htm" : " text/html; charset=utf-8" ,
88+ " .html" : " text/html; charset=utf-8" ,
89+ " .ico" : " image/vnd.microsoft.icon" ,
90+ " .jar" : " application/java-archive" ,
91+ " .jpeg" : " image/jpeg" ,
92+ " .jpg" : " image/jpeg" ,
93+ " .js" : " application/javascript" ,
94+ " .json" : " application/json" ,
95+ " .jsonld" : " application/ld+json" ,
96+ " .otf" : " font/otf" ,
97+ " .pdf" : " application/pdf" ,
98+ " .png" : " image/png" ,
99+ " .rss" : " application/rss+xml" ,
100+ " .svg" : " image/svg+xml" ,
101+ " .swf" : " application/x-shockwave-flash" ,
102+ " .ttf" : " font/ttf" ,
103+ " .txt" : " text/plain; charset=utf-8" ,
104+ " .weba" : " audio/webm" ,
105+ " .webm" : " video/webm" ,
106+ " .webp" : " image/webp" ,
107+ " .woff" : " font/woff" ,
108+ " .woff2" : " font/woff2" ,
109+ " .xhtml" : " application/xhtml+xml" ,
94110 " .xml" : " application/xml" ,
95111 " .wasm" : " application/wasm"
96112 }
@@ -100,6 +116,7 @@ module "template_files" {
100116
101117 base_dir = var. dist_folder
102118 file_types = local. known_mime_types
119+ depends_on = [" local_file.robots-txt" ]
103120}
104121resource "aws_s3_object" "app_storage" {
105122 for_each = module. template_files . files
0 commit comments