Skip to content

Commit

Permalink
Updated s3 resource
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfox675 committed May 16, 2022
1 parent b2d606e commit 7fe747a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# terraform-aws-s3-static-website

Used to publish static website files to an S3 bucket with proper MIME type

## Example

``` Terraform
module "s3-static-website" {
source = "Lupus-Metallum/s3-static-website/aws"
version = "1.0.6"
version = "1.1.0"
bucket_id = aws_s3_bucket.example.id
file_path = "${path.module}/src/my-website-files/" # Where your index.html and TLD web content lives
acl = "public-read"
storage_class = "STANDARD"
cache_control = "max-age=31536000"
bucket_id = aws_s3_bucket.example.id
file_path = "${path.module}/src/my-website-files/" # Where your index.html and TLD web content lives
acl = "public-read"
storage_class = "STANDARD"
cache_control = "max-age=31536000"
content_language = "en-US"
}
```
19 changes: 10 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
resource "aws_s3_bucket_object" "this" {
resource "aws_s3_object" "this" {
for_each = fileset(var.file_path, "**")

content_type = lookup(jsondecode(file("${path.module}/src/mime.json")), regex("\\.[^.]+$", each.value), null)
cache_control = var.cache_control
acl = var.acl
bucket = var.bucket_id
storage_class = var.storage_class
key = each.value
source = "${var.file_path}/${each.value}"
etag = filemd5("${var.file_path}/${each.value}")
content_type = lookup(jsondecode(file("${path.module}/src/mime.json")), regex("\\.[^.]+$", each.value), null)
content_language = var.content_language
cache_control = var.cache_control
acl = var.acl
bucket = var.bucket_id
storage_class = var.storage_class
key = each.value
source = "${var.file_path}/${each.value}"
etag = filemd5("${var.file_path}/${each.value}")
}
24 changes: 15 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
variable "bucket_id" {
type = string
type = string
description = "The bucket id to use as the destination for the static website"
}

variable "file_path" {
type = string
type = string
description = "The base filepath that contains the files to publish, you may need path.module/my/src/dir"
}

variable "acl" {
type = string
default = "public-read"
type = string
default = "public-read"
description = "The object acl to use for this site, defaults to public-read"
}

variable "storage_class" {
type = string
default = "STANDARD"
type = string
default = "STANDARD"
description = "The object storage class to use for this site, defaults to STANDARD"
}

variable "cache_control" {
type = string
default = "max-age=1440"
type = string
default = "max-age=1440"
description = "The header to use for cache control"
}
}

variable "content_language" {
type = string
default = "en-US"
description = "en-US or en-GB for language header?"
}

0 comments on commit 7fe747a

Please sign in to comment.