-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudfront.tf
118 lines (103 loc) · 2.96 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
module "cloudfront" {
source = "terraform-aws-modules/cloudfront/aws"
version = "~> 2.9.3"
aliases = [var.domain_name, "${var.subdomain}.${var.domain_name}"]
is_ipv6_enabled = true
## PriceClass_All is most expensive: check where your audience lives!
# price_class = "PriceClass_All"
# price_class = "PriceClass_200"
price_class = "PriceClass_100"
wait_for_deployment = false
origin = {
default = {
domain_name = "origin.${var.domain_name}"
custom_origin_config = {
http_port = 80
https_port = 443
origin_protocol_policy = "https-only"
origin_ssl_protocols = ["TLSv1.2"]
}
## do not uncomment these lines with `enabled = false` or terraform keeps
## complaining about the changes that don't exist
# origin_shield = {
# ## origin shield incurs extra charges
# enabled = true
# origin_shield_region = var.aws_region
# }
}
}
default_cache_behavior = {
target_origin_id = "default"
viewer_protocol_policy = "redirect-to-https"
compress = true
query_string = true
allowed_methods = [
"HEAD",
"GET",
"OPTIONS",
"PUT",
"PATCH",
"POST",
"DELETE"
]
cached_methods = [
"HEAD",
"GET",
]
}
viewer_certificate = {
acm_certificate_arn = module.acm.acm_certificate_arn
ssl_support_method = "sni-only"
}
tags = var.tags
}
module "acm" {
source = "terraform-aws-modules/acm/aws"
version = "~> 3.4.1"
domain_name = var.domain_name
zone_id = data.aws_route53_zone.zone.id
subject_alternative_names = ["${var.subdomain}.${var.domain_name}"]
# the location must be us-east-1 for cloudfront to find the certificate
providers = {
aws = aws.virginia
}
}
module "records" {
source = "terraform-aws-modules/route53/aws//modules/records"
version = "2.0.0" # @todo: revert to "~> 2.0" once 2.1.0 is fixed properly
zone_id = data.aws_route53_zone.zone.zone_id
records = [
{
name = ""
type = "A"
alias = {
name = module.cloudfront.cloudfront_distribution_domain_name
zone_id = module.cloudfront.cloudfront_distribution_hosted_zone_id
}
},
{
name = var.subdomain
type = "A"
alias = {
name = module.cloudfront.cloudfront_distribution_domain_name
zone_id = module.cloudfront.cloudfront_distribution_hosted_zone_id
}
},
{
name = ""
type = "AAAA"
alias = {
name = module.cloudfront.cloudfront_distribution_domain_name
zone_id = module.cloudfront.cloudfront_distribution_hosted_zone_id
}
},
{
name = var.subdomain
type = "AAAA"
alias = {
name = module.cloudfront.cloudfront_distribution_domain_name
zone_id = module.cloudfront.cloudfront_distribution_hosted_zone_id
}
},
]
}