-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcloudfront.tf
102 lines (85 loc) · 2.57 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
100
101
102
resource "aws_cloudfront_origin_access_identity" "default" {
count = var.use_s3_origin_identity ? 1 : 0
}
resource "aws_cloudfront_distribution" "cdn" {
enabled = true
default_root_object = "index.html"
is_ipv6_enabled = true
tags = var.tags
origin {
domain_name = var.use_s3_origin_identity ? aws_s3_bucket.bucket.bucket_regional_domain_name : aws_s3_bucket.bucket.website_endpoint
origin_id = "origin.${local.domain_name}"
dynamic "s3_origin_config" {
iterator = access
for_each = var.use_s3_origin_identity ? [42] : [0]
content {
origin_access_identity = aws_cloudfront_origin_access_identity.default[0].cloudfront_access_identity_path
}
}
dynamic "custom_origin_config" {
for_each = var.use_s3_origin_identity ? [] : [42]
content {
http_port = 80
https_port = 443
origin_protocol_policy = "http-only"
origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"]
}
}
}
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
forwarded_values {
cookies {
forward = "none"
}
query_string = var.forward_query_string
}
target_origin_id = "origin.${local.domain_name}"
viewer_protocol_policy = "redirect-to-https"
dynamic "lambda_function_association" {
iterator = lambda
for_each = var.lambda_associations
content {
event_type = lambda.value["event_type"]
lambda_arn = lambda.value["lambda_arn"]
}
}
}
web_acl_id = var.waf_id
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
cloudfront_default_certificate = false
acm_certificate_arn = module.certificate.arn
ssl_support_method = "sni-only"
minimum_protocol_version = "TLSv1.1_2016"
}
aliases = [
local.domain_name,
]
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#custom-error-response-arguments
custom_error_response {
error_caching_min_ttl = 0
error_code = 500
}
custom_error_response {
error_caching_min_ttl = 0
error_code = 502
}
custom_error_response {
error_caching_min_ttl = 0
error_code = 503
}
custom_error_response {
error_caching_min_ttl = 0
error_code = 504
}
logging_config {
bucket = aws_s3_bucket.logs_bucket.bucket_domain_name
include_cookies = false
}
}