-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudfront.tf
79 lines (63 loc) · 2.38 KB
/
cloudfront.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
resource "aws_cloudfront_origin_access_control" "static_site_identity" {
name = "cc-static-site-${var.tenant_vars.product}-${var.tenant_vars.component}"
description = "Origin access control for ${var.tenant_vars.product} ${var.tenant_vars.component}"
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
}
resource "aws_cloudfront_distribution" "static_site_distribution" {
origin {
domain_name = aws_s3_bucket.static_site.bucket_regional_domain_name
origin_id = aws_s3_bucket.static_site.id
origin_access_control_id = aws_cloudfront_origin_access_control.static_site_identity.id
}
enabled = true
is_ipv6_enabled = true
comment = "Cloudfront distribution for ${var.tenant_vars.product} ${var.tenant_vars.component}"
default_root_object = "index.html"
# logging_config {
# include_cookies = false
# bucket = "mylogs.s3.amazonaws.com"
# prefix = "myprefix"
# }
aliases = var.tenant_vars.cloudfront_aliases
default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD"]
target_origin_id = aws_s3_bucket.static_site.id
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 0
max_ttl = 86400
function_association {
event_type = "viewer-request"
function_arn = var.tenant_vars.cloudfront_function_rewrite_arn
}
}
custom_error_response {
error_code = 404
response_page_path = "/404.html" # Path to your custom error page
response_code = 404
error_caching_min_ttl = 10 # Cache TTL in seconds
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
price_class = var.cloud_front_default_vars.cloudfront_price_class
tags = local.common_tags
viewer_certificate {
acm_certificate_arn = var.tenant_vars.cloudfront_cert
minimum_protocol_version = "TLSv1.2_2021"
cloudfront_default_certificate = "false"
ssl_support_method = "sni-only"
}
web_acl_id = var.waf_arn
}