generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cloudfront.tf
99 lines (80 loc) · 2.95 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
# Cloudfront distribution using the static website S3 bucket as its origin
#
resource "aws_cloudfront_origin_access_identity" "simple_static_website" {
comment = "Allow CloudFront to reach the S3 bucket for domain ${var.domain_name_source}"
}
resource "aws_cloudfront_distribution" "simple_static_website" {
http_version = "http2"
origin {
domain_name = aws_s3_bucket.this.bucket_regional_domain_name
origin_id = "simple_static_website"
s3_origin_config {
origin_access_identity = aws_cloudfront_origin_access_identity.simple_static_website.cloudfront_access_identity_path
}
}
default_root_object = var.index_document
enabled = true
aliases = [var.domain_name_source]
price_class = var.cloudfront_price_class
default_cache_behavior {
target_origin_id = "simple_static_website"
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD"]
compress = true
forwarded_values {
query_string = var.cloudfront_query_string_forwarding
cookies {
forward = "none"
}
}
dynamic "lambda_function_association" {
for_each = var.lambda_function_association
content {
event_type = lookup(lambda_function_association.value, "event_type", null)
include_body = lookup(lambda_function_association.value, "include_body", false)
lambda_arn = lookup(lambda_function_association.value, "lambda_arn", null)
}
}
# Function association
dynamic "function_association" {
for_each = var.function_association
content {
event_type = lookup(function_association.value, "event_type", null)
function_arn = lookup(function_association.value, "function_arn", null)
}
}
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 86400
max_ttl = 86400
}
dynamic "custom_error_response" {
for_each = var.single_page_app ? [
{
error_code = 403,
response_page_path = "/${var.index_document}",
error_caching_min_ttl = 300,
response_code = 200
}
] : var.custom_error_responses
content {
error_code = custom_error_response.value.error_code
error_caching_min_ttl = custom_error_response.value.error_caching_min_ttl != null ? custom_error_response.value.error_caching_min_ttl : 300
response_code = custom_error_response.value.response_code != null ? custom_error_response.value.response_code : 200
response_page_path = custom_error_response.value.response_page_path
}
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = local.acm_certificate_arn
ssl_support_method = "sni-only"
minimum_protocol_version = "TLSv1.2_2021"
}
web_acl_id = var.web_acl_arn
tags = local.common_tags
}