Skip to content

Commit

Permalink
Add ipv6 and 404 response code options (#38)
Browse files Browse the repository at this point in the history
* Add not-found-response-code variable

* Add option for IPv6

* Fix readme
  • Loading branch information
dchesterton authored Apr 6, 2020
1 parent e71fe5e commit ec3fc23
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ See the [Terraform Modules documentation](https://www.terraform.io/docs/modules/
* `default-root-object`: (Optional) default root object to be served by CloudFront. Defaults to `index.html`, but can be e.x. `v1.0.0/index.html` for versioned applications.
* `not-found-response-path`: response path for the file that should be served on 404. Default to `/404.html`,
but can be e.x. `/index.html` for single page applications.
* `not-found-response-code`: response code when serving a 404 page. Defaults to `200`.
* `trusted_signers`: (Optional) List of AWS account IDs that are allowed to create signed URLs for this
distribution. May contain `self` to indicate the account where the distribution is created in.
* `tags`: (Optional) Additional key/value pairs to set as tags.
* `forward-query-string`: (Optional) Forward the query string to the origin. Default value = `false`
* `price_class`: (Optional) The price class that corresponds with the maximum price that you want to pay for CloudFront service.
Read [pricing page](https://aws.amazon.com/cloudfront/pricing/) for more details.
Options: `PriceClass_100` | `PriceClass_200` | `PriceClass_All`. Default value = `PriceClass_200`
* `ipv6`: (Optional) Enable IPv6 support on CloudFront distribution. Default value = `false`

### Outputs

Expand Down Expand Up @@ -141,6 +143,7 @@ See the [Terraform Modules documentation](https://www.terraform.io/docs/modules/
* `price_class`: (Optional) The price class that corresponds with the maximum price that you want to pay for CloudFront service.
Read [pricing page](https://aws.amazon.com/cloudfront/pricing/) for more details.
Options: `PriceClass_100` | `PriceClass_200` | `PriceClass_All`. Default value = `PriceClass_200`
* `ipv6`: (Optional) Enable IPv6 support on CloudFront distribution. Default value = `false`

### Outputs

Expand Down
9 changes: 5 additions & 4 deletions site-main/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ resource "aws_iam_policy_attachment" "site-deployer-attach-user-policy" {
## Create a Cloudfront distribution for the static website
################################################################################################################
resource "aws_cloudfront_distribution" "website_cdn" {
enabled = true
price_class = var.price_class
http_version = "http2"
enabled = true
is_ipv6_enabled = var.ipv6
price_class = var.price_class
http_version = "http2"

origin {
origin_id = "origin-bucket-${aws_s3_bucket.website_bucket.id}"
Expand All @@ -109,7 +110,7 @@ resource "aws_cloudfront_distribution" "website_cdn" {
custom_error_response {
error_code = "404"
error_caching_min_ttl = "360"
response_code = "200"
response_code = var.not-found-response-code
response_page_path = var.not-found-response-path
}

Expand Down
11 changes: 11 additions & 0 deletions site-main/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ variable "not-found-response-path" {
default = "/404.html"
}

variable "not-found-response-code" {
type = string
default = "200"
}

variable "tags" {
type = map(string)
description = "Optional Tags"
Expand All @@ -60,3 +65,9 @@ variable "price_class" {
description = "CloudFront price class"
default = "PriceClass_200"
}

variable "ipv6" {
type = bool
description = "Enable IPv6 on CloudFront distribution"
default = false
}
7 changes: 4 additions & 3 deletions site-redirect/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ resource "aws_iam_policy_attachment" "staging-site-deployer-attach-user-policy"
## Create a Cloudfront distribution for the static website
################################################################################################################
resource "aws_cloudfront_distribution" "website_cdn" {
enabled = true
price_class = var.price_class
http_version = "http2"
enabled = true
is_ipv6_enabled = var.ipv6
price_class = var.price_class
http_version = "http2"

origin {
origin_id = "origin-bucket-${aws_s3_bucket.website_bucket.id}"
Expand Down
6 changes: 6 additions & 0 deletions site-redirect/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ variable "price_class" {
default = "PriceClass_200"
}

variable "ipv6" {
type = bool
description = "Enable IPv6 on CloudFront distribution"
default = false
}

variable "default_root_object" {
type = string
description = "CloudFront default root object"
Expand Down

0 comments on commit ec3fc23

Please sign in to comment.