Skip to content

Commit

Permalink
adds support for many more file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel.schroeder committed Nov 15, 2019
1 parent 9759b4a commit a6141b3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 26 deletions.
52 changes: 38 additions & 14 deletions README.md
Expand Up @@ -17,7 +17,7 @@ The module **does not** take care of the DNS record. You need to create a CNAME
```hcl
module "s3-cloudfront-page" {
source = "udondan/s3-cloudfront-page/aws"
version = "0.1.0"
version = "0.2.0"
domain_name = "www.example.com" // www. or any other subdomain is mandatory! Apex records are not supported at this time
root = "./public"
}
Expand Down Expand Up @@ -48,48 +48,72 @@ When initially applying, bring some patience. Creating a new CloudFront distribu

---

In case your public folder contains content you do not want to sync to s3, you can provide a filter. This might be interesting if you use JavaScript or font libraries which contain files you don't need to serve to customers. E.g. [Font Awesome](https://fontawesome.com/) contains some 1700 sprite and svg files not required by the frontend. You can filter them like so:
In case your public folder contains content you do not want to sync to s3, you can provide a filter. This might be interesting if you use JavaScript or font libraries which contain files you don't need to serve to customers. E.g. [Font Awesome](https://fontawesome.com/) contains some 1600 sprite and svg files not required by the frontend. You can filter them like so:

```hcl
module "s3-cloudfront-page" {
source = "udondan/s3-cloudfront-page/aws"
version = "0.1.0"
version = "0.2.0"
domain_name = "www.example.com"
root = "./public"
filter_paths = ".*/font-awesome/(sprites|svgs)/.*"
}
```

Why should you care? Each file will be synced by Terraform as a separate resource. Even when there are no changes, Terraform will require quite some time to compare the state with the local files.

---

By default only file with these extensions will be synced to S3:

- html
- css
- js
- pdf
- ico
- png
- doc
- docx
- dot
- eot
- gif
- jpg
- gz
- htm
- html
- ico
- jpeg
- jpg
- js
- json
- map
- eot
- mp3
- mp4
- mpeg
- pdf
- png
- pot
- pps
- ppt
- ppz
- rtf
- svg
- tar
- tif
- tiff
- ttf
- txt
- woff
- woff2
- xls
- xlsx
- xml
- zip

If you need to sync additional file types, you need to provide the expected mime type:

```hcl
module "s3-cloudfront-page" {
source = "udondan/s3-cloudfront-page/aws"
version = "0.1.0"
version = "0.2.0"
domain_name = "www.example.com"
root = "./public"
additional_filetypes = {
zip = "application/zip",
mp3 = "audio/mpeg",
mp4 = "video/mp4",
swf = "application/x-shockwave-flash"
}
}
```
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
v0.1.0
v0.2.0
56 changes: 45 additions & 11 deletions locals.tf
Expand Up @@ -10,21 +10,55 @@ locals {
)
)
default_filetypes = { // Only files types in this list will be synced to S3
html = "text/html"
css = "text/css"
js = "text/javascript"
pdf = "application/pdf"
ico = "image/x-icon"
png = "image/png"
gif = "image/gif"
jpg = "image/jpeg"
jpeg = "image/jpeg"
map = "application/json"

// common web documents
css = "text/css"
htm = "text/html"
html = "text/html"
js = "text/javascript"
json = "application/json"
map = "application/json"
xml = "application/xml"

// images
gif = "image/gif"
ico = "image/x-icon"
jpeg = "image/jpeg"
jpg = "image/jpeg"
png = "image/png"
svg = "image/svg+xml"
tif = "image/tiff"
tiff = "image/tiff"

// fonts
eot = "application/vnd.ms-fontobject"
svg = "image/svg+xml"
ttf = "font/ttf"
woff = "font/woff"
woff2 = "font/woff2"

// archives
gz = "application/gzip"
tar = "application/gzip"
zip = "application/zip"

// media
mp3 = "audio/mpeg"
mp4 = "video/mp4"
mpeg = "video/mpeg"

// documents
doc = "application/msword"
docx = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
dot = "application/msword"
pdf = "application/pdf"
pot = "application/mspowerpoint"
pps = "application/mspowerpoint"
ppt = "application/mspowerpoint"
ppz = "application/mspowerpoint"
rtf = "application/rtf"
txt = "text/plain"
xls = "application/vnd.ms-excel"
xlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
valid_files = merge(local.default_filetypes, var.additional_filetypes)
}

0 comments on commit a6141b3

Please sign in to comment.