forked from jonathanio/terraform-module-s3-cloudfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudfront.tf
70 lines (54 loc) · 1.89 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
resource "aws_cloudfront_distribution" "website" {
enabled = true
is_ipv6_enabled = true
http_version = "http2"
aliases = ["${compact(concat(list(var.hostname),var.aliases))}"]
viewer_certificate {
acm_certificate_arn = "${data.aws_acm_certificate.frontend.arn}"
minimum_protocol_version = "TLSv1"
ssl_support_method = "sni-only"
}
origin {
domain_name = "${aws_s3_bucket.content.bucket_domain_name}"
origin_id = "${aws_s3_bucket.content.id}"
s3_origin_config {
origin_access_identity = "${aws_cloudfront_origin_access_identity.website.cloudfront_access_identity_path}"
}
}
default_root_object = "index.html"
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "${aws_s3_bucket.content.id}"
compress = true
viewer_protocol_policy = "redirect-to-https"
default_ttl = "${var.cache_ttl}"
min_ttl = "${(var.cache_ttl / 4) < 60 ? 0 : floor(var.cache_ttl / 4)}"
max_ttl = "${floor(var.cache_ttl * 24)}"
forwarded_values {
query_string = false
headers = ["Origin"]
cookies {
forward = "none"
}
}
}
// 100: Limit to only Europe, USA, and Canada endpoints.
// 200: + Hong Kong, Philippines, South Korea, Singapore, & Taiwan.
// All: + South America, and Australa.
price_class = "${var.price_class}"
restrictions {
geo_restriction {
restriction_type = "none"
}
}
logging_config {
include_cookies = false
bucket = "${aws_s3_bucket.logs.bucket_domain_name}"
prefix = "${var.hostname}/cloudfront"
}
tags = "${merge(var.tags, map("Name", format("s3-cloudfront-%s-distribution", var.name)))}"
}
resource "aws_cloudfront_origin_access_identity" "website" {
comment = "CloudFront OAI for ${var.name} (${var.hostname})"
}