forked from QuiNovas/terraform-aws-cloudfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
116 lines (111 loc) · 4.49 KB
/
main.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
103
104
105
106
107
108
109
110
111
112
113
114
115
data "aws_s3_bucket" "log_bucket" {
bucket = var.log_bucket
}
resource "aws_cloudfront_origin_access_identity" "origin" {
comment = var.distribution_name
}
resource "aws_cloudfront_distribution" "distribution" {
aliases = var.aliases
comment = var.comment
dynamic "custom_error_response" {
for_each = var.custom_error_response
content {
error_caching_min_ttl = lookup(custom_error_response.value, "error_caching_min_ttl", null)
error_code = custom_error_response.value.error_code
response_code = lookup(custom_error_response.value, "response_code", null)
response_page_path = lookup(custom_error_response.value, "response_page_path", null)
}
}
default_cache_behavior {
allowed_methods = [
"HEAD",
"GET",
]
cached_methods = [
"HEAD",
"GET",
]
default_ttl = 3600
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
lambda_function_association {
event_type = "origin-request"
lambda_arn = aws_lambda_function.redirector.qualified_arn
}
max_ttl = 86400
min_ttl = 0
target_origin_id = var.distribution_name
viewer_protocol_policy = "redirect-to-https"
}
default_root_object = var.default_root_object
depends_on = [aws_lambda_permission.redirector]
enabled = true
is_ipv6_enabled = true
lifecycle {
ignore_changes = [default_cache_behavior]
}
logging_config {
bucket = data.aws_s3_bucket.log_bucket.bucket_domain_name
include_cookies = false
prefix = "cloudfront/${var.distribution_name}/"
}
dynamic "ordered_cache_behavior" {
for_each = var.ordered_cache_behavior
content {
allowed_methods = ordered_cache_behavior.value.allowed_methods
cached_methods = ordered_cache_behavior.value.cached_methods
compress = lookup(ordered_cache_behavior.value, "compress", null)
default_ttl = lookup(ordered_cache_behavior.value, "default_ttl", null)
field_level_encryption_id = lookup(ordered_cache_behavior.value, "field_level_encryption_id", null)
max_ttl = lookup(ordered_cache_behavior.value, "max_ttl", null)
min_ttl = lookup(ordered_cache_behavior.value, "min_ttl", null)
path_pattern = ordered_cache_behavior.value.path_pattern
smooth_streaming = lookup(ordered_cache_behavior.value, "smooth_streaming", null)
target_origin_id = ordered_cache_behavior.value.target_origin_id
trusted_signers = lookup(ordered_cache_behavior.value, "trusted_signers", null)
viewer_protocol_policy = ordered_cache_behavior.value.viewer_protocol_policy
forwarded_values {
headers = lookup(ordered_cache_behavior.value.forwarded_values, "headers", null)
query_string = ordered_cache_behavior.value.forwarded_values.query_string
query_string_cache_keys = lookup(ordered_cache_behavior.value.forwarded_values, "query_string_cache_keys", null)
cookies {
forward = ordered_cache_behavior.value.forwarded_values.cookies.forward
whitelisted_names = lookup(ordered_cache_behavior.value.forwarded_values.cookies, "whitelisted_names", null)
}
}
dynamic "lambda_function_association" {
for_each = ordered_cache_behavior.value.lambda_function_association
content {
event_type = lambda_function_association.value.event_type
include_body = lambda_function_association.value.include_body
lambda_arn = lambda_function_association.value.lambda_arn
}
}
}
}
origin {
domain_name = aws_s3_bucket.origin.bucket_domain_name
origin_id = var.distribution_name
s3_origin_config {
origin_access_identity = aws_cloudfront_origin_access_identity.origin.cloudfront_access_identity_path
}
}
price_class = var.price_class
restrictions {
geo_restriction {
restriction_type = "none"
}
}
tags = local.tags
viewer_certificate {
acm_certificate_arn = var.acm_certificate_arn
ssl_support_method = var.acm_certificate_arn == "" ? null : "sni-only"
minimum_protocol_version = var.acm_certificate_arn == "" ? "TLSv1" : "TLSv1.1_2016"
cloudfront_default_certificate = var.acm_certificate_arn == "" ? true : false
}
web_acl_id = var.web_acl_id
}