Skip to content

Commit d962d2f

Browse files
committed
Added support for cloudfront_custom_errors configuration block on the CloudFront Distribution to support React client side routing
1 parent 5694dff commit d962d2f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cloudfront.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ resource "aws_cloudfront_distribution" "cdn" {
1111
comment = var.comment
1212
default_root_object = var.index_document_default
1313

14+
15+
dynamic "custom_error_response" {
16+
for_each = var.cloudfront_custom_errors
17+
content {
18+
error_caching_min_ttl = custom_error_response.value["error_caching_min_ttl"]
19+
error_code = custom_error_response.value["error_code"]
20+
response_code = custom_error_response.value["response_code"]
21+
response_page_path = custom_error_response.value["response_page_path"]
22+
}
23+
}
24+
1425
default_cache_behavior {
1526
allowed_methods = var.cloudfront_allowed_methods
1627
cached_methods = var.cloudfront_cached_methods

vars.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ variable "url" {
5454
description = "The custom URL to access the site. Must match the certificate name to provide a valid TLS connection."
5555
}
5656

57+
variable cloudfront_custom_errors {
58+
description = "A map of custom error settings for the CloudFront Distribution"
59+
type = list(object({
60+
error_caching_min_ttl = number
61+
error_code = number
62+
response_code = number
63+
response_page_path = string
64+
}))
65+
default = []
66+
}
5767
variable "cloudfront_allowed_methods" {
5868
description = " Controls which HTTP methods CloudFront processes and forwards to your Amazon S3 bucket or your custom origin."
5969
type = list(string)

0 commit comments

Comments
 (0)