Skip to content

Commit

Permalink
Merge pull request #25 from babbel/custom-error-response
Browse files Browse the repository at this point in the history
Add custom_error_response variable
  • Loading branch information
fmasuhr authored Aug 9, 2024
2 parents 06cdf49 + 66dc5b5 commit e030e0c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions _test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ module "s3-bucket-with-cloudfront-with-custom-cert" {
acm_certificate = {
arn = "arn:aws:acm:eu-west-1:123456789012:certificate/12345678-1234-1234-1234-123456789012"
}

custom_error_response = [{
error_code = 403
response_page_path = "/404.html"
response_code = 404
error_caching_min_ttl = null
}]
}
11 changes: 11 additions & 0 deletions cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ resource "aws_cloudfront_distribution" "this" {
}
}

dynamic "custom_error_response" {
for_each = var.custom_error_response

content {
error_caching_min_ttl = custom_error_response.error_caching_min_ttl
error_code = custom_error_response.error_code
response_code = custom_error_response.response_code
response_page_path = custom_error_response.response_page_path
}
}

tags = var.tags
}

Expand Down
15 changes: 15 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ variable "bucket_name" {
description = "Name of the S3 bucket to create"
}

variable "custom_error_response" {
type = list(
object({
error_caching_min_ttl = number
error_code = number
response_code = number
response_page_path = string
})
)

default = []

description = "One or more custom error response elements to be used for the CloudFront distribution"
}

variable "default_root_object" {
type = string
default = null
Expand Down

0 comments on commit e030e0c

Please sign in to comment.