Skip to content

Commit a25f31a

Browse files
authored
Merge pull request #2 from eabdelmaqsod/feature/add_custom_error_responce
Feature/add custom error responce
2 parents cea68f2 + db983b7 commit a25f31a

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 0.0.2 (Unreleased)
2+
ENHANCEMENTS:
3+
4+
* Add custom response error referrenced in issue ([#3](https://github.com/zoitech/terraform-aws-cloudfront/issues/3))
5+
* Add default_cache_behavior ( header )

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ module "my_cloudfront" {
3939
# Default Cache Behavior Settings
4040
default_cache_behavior_allowed_methods = ["GET", "HEAD"]
4141
default_cache_behavior_cached_methods = ["GET", "HEAD"]
42+
default_cache_behavior_forwarded_values_headers = ["origin"]
4243
target_origin_id = "s3-my-origin-id"
4344
viewer_protocol_policy = "redirect-to-https"
4445
price_class = "PriceClass_100"
4546
47+
# Custom Error Response
48+
custom_error_response = [
49+
{
50+
error_caching_min_ttl = "86400" #Optional
51+
error_code = "404" #Required
52+
response_code = "200" #Optional
53+
response_page_path = "/index.html"} #Optional
54+
]
55+
4656
# Geo Restrictions
4757
restriction_type = "none"
4858

cloudfront.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ resource "aws_cloudfront_distribution" "distribution" {
1818
bucket = "${var.logging_config_bucket}"
1919
prefix = "${var.logging_config_prefix}"
2020
}
21-
21+
2222
aliases = "${var.aliases}" #list
2323

24+
# Custom Error response
25+
custom_error_response = ["${var.custom_error_response}" ] #list
26+
2427
default_cache_behavior {
2528
allowed_methods = "${var.default_cache_behavior_allowed_methods}" #list
2629
cached_methods = "${var.default_cache_behavior_cached_methods}" #list
@@ -32,6 +35,8 @@ resource "aws_cloudfront_distribution" "distribution" {
3235
cookies {
3336
forward = "none"
3437
}
38+
39+
headers = "${var.default_cache_behavior_forwarded_values_headers}" #list
3540
}
3641

3742
viewer_protocol_policy = "${var.viewer_protocol_policy}"

variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ variable "default_cache_behavior_cached_methods" {
5858
description = "(Required) - Controls whether CloudFront caches the response to requests using the specified HTTP methods."
5959
}
6060

61+
variable "default_cache_behavior_forwarded_values_headers" {
62+
type = "list"
63+
description = "(Required) - Specifies the Headers, if any, that you want CloudFront to vary upon for this cache behavior. Specify * to include all headers."
64+
}
65+
6166
variable "target_origin_id" {
6267
description = "(Required) - The value of ID for the origin that you want CloudFront to route requests to when a request matches the path pattern either for a cache behavior or for the default cache behavior."
6368
}
@@ -91,3 +96,9 @@ variable "minimum_protocol_version" {
9196
variable "ssl_support_method" {
9297
description = "Specifies how you want CloudFront to serve HTTPS requests. One of vip or sni-only. Required if you specify acm_certificate_arn or iam_certificate_id. NOTE: vip causes CloudFront to use a dedicated IP address and may incur extra charges."
9398
}
99+
100+
variable "custom_error_response" {
101+
description = "(Optional) - One or more custom error response elements (multiples allowed)."
102+
type = "list"
103+
default = []
104+
}

0 commit comments

Comments
 (0)