-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudfront.tf
58 lines (48 loc) · 1.64 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
data "aws_cloudfront_cache_policy" "this" {
name = "Managed-CachingOptimized"
}
resource "aws_cloudfront_origin_access_control" "this" {
name = local.fqdn
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
}
resource "aws_cloudfront_response_headers_policy" "this" {
name = replace("Cache-Control-${local.fqdn}",".","_")
custom_headers_config {
items {
header = "Cache-Control"
override = true
value = "max-age=31536000"
}
}
}
resource "aws_cloudfront_distribution" "this" {
origin {
domain_name = resource.aws_s3_bucket.this.bucket_regional_domain_name
origin_id = resource.aws_s3_bucket.this.bucket_regional_domain_name
origin_access_control_id = aws_cloudfront_origin_access_control.this.id
}
aliases = [local.fqdn]
enabled = true
default_cache_behavior {
cache_policy_id = data.aws_cloudfront_cache_policy.this.id
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = resource.aws_s3_bucket.this.bucket_regional_domain_name
response_headers_policy_id = aws_cloudfront_response_headers_policy.this.id
viewer_protocol_policy = "allow-all"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = aws_acm_certificate.this.id
ssl_support_method = "sni-only"
}
}