-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudfront.tf
66 lines (54 loc) · 1.92 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
# Cloudfront distribution for main s3 site.
resource "aws_cloudfront_distribution" "blog_distribution" {
origin {
domain_name = aws_s3_bucket.blog_assets.bucket_regional_domain_name
origin_id = "S3-${var.bucket_name}"
origin_access_control_id = aws_cloudfront_origin_access_control.blog_distribution_origin_access.id
}
enabled = true
is_ipv6_enabled = true
default_root_object = "index.html"
aliases = ["www.${var.domain_name}", "${var.domain_name}"]
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "S3-${var.bucket_name}"
dynamic "lambda_function_association" {
for_each = var.lambda_associations
content {
event_type = lambda_function_association.value.event_type
lambda_arn = module.edge-functions.function_arns["${lambda_function_association.value.lambda_name}"]
}
}
forwarded_values {
headers = ["X-Request-Prerender", "X-Prerender-Host"]
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "redirect-to-https"
min_ttl = 31536000
default_ttl = 31536000
max_ttl = 31536000
compress = true
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = var.ssl_certificate_arn
ssl_support_method = "sni-only"
minimum_protocol_version = "TLSv1.1_2016"
}
tags = var.common_tags
}
# Cloudfront distribution for assets s3 site.
resource "aws_cloudfront_origin_access_control" "blog_distribution_origin_access" {
name = "blog_distribution_origin_access"
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
}