Skip to content

Commit 17a58c8

Browse files
authored
DT-187: Add custom error page for Delta website CloudFront
1 parent b370a37 commit 17a58c8

File tree

13 files changed

+8996
-3
lines changed

13 files changed

+8996
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ CloudFront distributions with HTTPS aliases require valid SSL certificates to cr
241241
If you're creating the distributions without valid SSL certificates (for example, so that you can give DLUHC all the records in one go)
242242
then set `domain = null` for each distribution to create without aliases.
243243

244+
The production Delta website has an origin read timeout above the standard quota limit of 60 seconds, so request an increase through the console if you're using that.
245+
244246
```sh
245247
terraform apply -target module.public_albs -target module.cloudfront_distributions
246248
```

terraform/modules/cloudfront_distribution/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ variable "apply_aws_shield" {
4949
variable "function_associations" {
5050
type = list(object({ event_type = string, function_arn = string }))
5151
default = []
52-
}
52+
}

terraform/modules/cloudfront_distributions/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module "api_auth_waf" {
4949
}
5050

5151
module "delta_cloudfront" {
52-
source = "../cloudfront_distribution"
52+
source = "../website_cloudfront"
5353
prefix = "delta-${var.environment}-"
5454
access_logs_bucket_domain_name = module.access_logs_bucket.bucket_domain_name
5555
access_logs_prefix = "delta"
@@ -60,6 +60,7 @@ module "delta_cloudfront" {
6060
is_ipv6_enabled = var.delta.ip_allowlist == null
6161
geo_restriction_countries = var.delta.geo_restriction_countries
6262
apply_aws_shield = var.apply_aws_shield
63+
origin_read_timeout = var.delta.origin_read_timeout
6364
}
6465

6566
module "api_cloudfront" {

terraform/modules/cloudfront_distributions/variables.tf

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ variable "delta" {
4141
# Leave null to disable restrictions
4242
geo_restriction_countries = optional(list(string))
4343
ip_allowlist = optional(list(string))
44+
origin_read_timeout = optional(number)
4445
})
4546
}
4647

terraform/modules/waf/main.tf

+12-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ resource "aws_wafv2_web_acl" "waf_acl" {
126126
}
127127
}
128128

129+
custom_response_body {
130+
key = "ip_error"
131+
content = "This resource is not available to your IP address"
132+
content_type = "TEXT_PLAIN"
133+
}
134+
129135
# Either use the AWS managed IP reputation list, or an explicit allowlist
130136
dynamic "rule" {
131137
for_each = local.ip_reputation_enabled
@@ -158,7 +164,12 @@ resource "aws_wafv2_web_acl" "waf_acl" {
158164
name = "ip-allowlist"
159165
priority = 4
160166
action {
161-
block {}
167+
block {
168+
custom_response {
169+
custom_response_body_key = "ip_error"
170+
response_code = 403
171+
}
172+
}
162173
}
163174

164175
statement {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "aws_cloudfront_origin_access_control" "s3" {
2+
name = "${var.prefix}s3-control"
3+
description = "Access control for the static error pages s3 bucket"
4+
origin_access_control_origin_type = "s3"
5+
signing_behavior = "always"
6+
signing_protocol = "sigv4"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
provider "aws" {
2+
alias = "us-east-1"
3+
region = "us-east-1"
4+
}
5+
6+
resource "aws_acm_certificate_validation" "cloudfront_domains" {
7+
count = var.cloudfront_domain == null ? 0 : 1
8+
provider = aws.us-east-1
9+
certificate_arn = var.cloudfront_domain.acm_certificate_arn
10+
}

0 commit comments

Comments
 (0)