-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudfront.tf
More file actions
63 lines (53 loc) · 1.42 KB
/
Copy pathcloudfront.tf
File metadata and controls
63 lines (53 loc) · 1.42 KB
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
# Name for the origin
locals {
s3_origin_id = "s3-web-${aws_s3_bucket.site-bucket.id}"
}
# CF distribution
resource "aws_cloudfront_distribution" "site" {
origin {
origin_id = local.s3_origin_id
domain_name = aws_s3_bucket.site-bucket.website_endpoint
# Custom origin with S3 website as source
# This ensures subdirectories redirect to their associated index.html
custom_origin_config {
http_port = "80"
https_port = "443"
origin_protocol_policy = "http-only"
origin_ssl_protocols = ["TLSv1.2"]
}
}
enabled = true
is_ipv6_enabled = true
price_class = "PriceClass_100"
aliases = [
var.domain_name
]
default_root_object = "index.html"
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = local.s3_origin_id
viewer_protocol_policy = "redirect-to-https"
compress = true
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = aws_acm_certificate.site.arn
ssl_support_method = "sni-only"
}
logging_config {
include_cookies = false
bucket = aws_s3_bucket.site-logs.bucket_domain_name
prefix = "${var.domain_name}/cf/"
}
}