generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudfront.tf
92 lines (74 loc) · 2.34 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
resource "aws_cloudfront_distribution" "superset_docs" {
enabled = true
aliases = [var.domain]
price_class = "PriceClass_100"
web_acl_id = aws_wafv2_web_acl.superset_docs.arn
origin {
domain_name = local.superset_docs_function_url
origin_id = module.superset_docs.function_name
custom_origin_config {
http_port = 80
https_port = 443
origin_read_timeout = 60
origin_protocol_policy = "https-only"
origin_ssl_protocols = ["TLSv1.2"]
}
}
default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD"]
forwarded_values {
query_string = true
cookies {
forward = "none"
}
}
target_origin_id = module.superset_docs.function_name
viewer_protocol_policy = "redirect-to-https"
min_ttl = 1
default_ttl = 86400 # 24 hours
max_ttl = 86400 # 24 hours
compress = true
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = aws_acm_certificate_validation.superset_docs.certificate_arn
minimum_protocol_version = "TLSv1.2_2021"
ssl_support_method = "sni-only"
}
tags = local.common_tags
}
resource "aws_acm_certificate" "superset_docs" {
provider = aws.us-east-1
domain_name = var.domain
subject_alternative_names = ["*.${var.domain}"]
validation_method = "DNS"
tags = local.common_tags
lifecycle {
create_before_destroy = true
}
}
resource "aws_route53_record" "superset_docs_cert_validation" {
zone_id = var.hosted_zone_id
for_each = {
for dvo in aws_acm_certificate.superset_docs.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
type = dvo.resource_record_type
record = dvo.resource_record_value
}
}
allow_overwrite = true
name = each.value.name
records = [each.value.record]
type = each.value.type
ttl = 60
}
resource "aws_acm_certificate_validation" "superset_docs" {
provider = aws.us-east-1
certificate_arn = aws_acm_certificate.superset_docs.arn
validation_record_fqdns = [for record in aws_route53_record.superset_docs_cert_validation : record.fqdn]
}