-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
87 lines (69 loc) · 1.87 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
resource "aws_s3_bucket" "logs" {
bucket_prefix = "cdnlogs-${substr(
replace(var.domain, ".", "-"),
0,
min(28, length(var.domain)),
)}-"
acl = "private"
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}
# We expect the certificate for this domain to already be in ACM
data "aws_acm_certificate" "domain" {
provider = aws.us_east_aws
domain = var.domain
statuses = ["ISSUED"]
}
resource "aws_cloudfront_distribution" "distribution" {
aliases = [var.domain]
origin {
domain_name = var.origin
origin_id = var.domain
custom_origin_config {
http_port = 80
https_port = 443
origin_protocol_policy = "https-only"
origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"]
}
}
enabled = true
is_ipv6_enabled = true
web_acl_id = var.web_acl_id
logging_config {
include_cookies = false
bucket = aws_s3_bucket.logs.bucket_domain_name
}
default_cache_behavior {
allowed_methods = var.cache_allowed_methods
cached_methods = ["GET", "HEAD"]
target_origin_id = var.domain
forwarded_values {
query_string = var.forward_query_string
headers = var.forward_headers
cookies {
forward = var.forward_cookies
whitelisted_names = var.forward_cookies_whitelist
}
}
viewer_protocol_policy = "redirect-to-https"
min_ttl = var.min_ttl
default_ttl = var.default_ttl
max_ttl = var.max_ttl
}
price_class = "PriceClass_All"
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = data.aws_acm_certificate.domain.arn
minimum_protocol_version = "TLSv1.1_2016"
ssl_support_method = "sni-only"
}
}