Skip to content

Commit

Permalink
added website resources and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zachreborn committed Nov 24, 2023
1 parent 11db06b commit 3d071b7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/aws/s3/bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
}
}

resource "aws_s3_bucket_website_configuration" "this" {
count = var.enable_website ? 1 : 0
bucket = aws_s3_bucket.this.id
routing_rules = var.routing_rules

error_document {
key = var.error_document
}

index_document {
suffix = var.index_document
}

dynamic "redirect_all_requests_to" {
for_each = var.redirect_all_requests_to == null ? [] : [var.redirect_all_requests_to]
content {
host_name = redirect_all_requests_to.value.host_name
protocol = redirect_all_requests_to.value.protocol
}
}
}

resource "aws_s3_bucket_versioning" "this" {
count = var.versioning_status == "Enabled" ? 1 : 0
bucket = aws_s3_bucket.this.id
Expand Down
39 changes: 39 additions & 0 deletions modules/aws/s3/bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,34 @@ variable "sse_algorithm" {
}
}

######################
# S3 Website Variables
######################

variable "error_document" {
type = string
description = "(Optional) An absolute path to the document to return in case of a 4XX error."
default = "error.html"
}

variable "index_document" {
type = string
description = "(Optional) Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders."
default = "index.html"
}

variable "redirect_all_requests_to" {
type = any
description = "(Optional) A hostname to redirect all website requests for this bucket to. Hostname can optionally be prefixed with a protocol (http:// or https://) to use when redirecting requests. The default is the protocol that is used in the original request."
default = null
}

variable "routing_rules" {
type = any
description = "(Optional) A list of routing rules that can redirect requests to different directories or buckets. These rules are applied in the order that you specify them. For more information about routing rules, see Configuring advanced conditional redirects in the Amazon Simple Storage Service Developer Guide."
default = null
}

######################
# S3 Versioning Variables
######################
Expand Down Expand Up @@ -349,12 +377,23 @@ variable "enable_s3_bucket_logging" {
}
}

variable "enable_website" {
type = bool
description = "(Optional) Enable static website hosting for S3 bucket. If true, this will create a website configuration for the bucket. Defaults to false."
default = false
validation {
condition = can(regex("true|false", var.enable_website))
error_message = "The value must be true or false."
}
}

variable "expected_bucket_owner" {
type = string
description = "(Optional) Account ID of the expected bucket owner. If the bucket is owned by a different account, the request will fail with an HTTP 403 (Access Denied) error."
default = null
}


variable "tags" {
type = map(any)
description = "(Optional) A mapping of tags to assign to the bucket."
Expand Down

0 comments on commit 3d071b7

Please sign in to comment.