-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
98 lines (80 loc) · 3.35 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
87
88
89
90
91
92
93
94
95
96
97
98
resource "aws_cloudfront_distribution" "cloudfront" {
enabled = var.cloudfront_enable
default_root_object = var.default_root_object
aliases = var.aliases
is_ipv6_enabled = var.is_ipv6_enabled
custom_error_response {
error_caching_min_ttl = var.custom_error_response["error_caching_min_ttl"]
error_code = var.custom_error_response["error_code"]
response_code = var.custom_error_response["response_code"]
response_page_path = var.custom_error_response["response_page_path"]
}
default_cache_behavior {
allowed_methods = var.default_cache_behavior["allowed_methods"]
cached_methods = var.default_cache_behavior["cached_methods"]
target_origin_id = var.default_cache_behavior["target_origin_id"]
compress = var.default_cache_behavior["compress"]
viewer_protocol_policy = var.default_cache_behavior["viewer_protocol_policy"]
min_ttl = var.default_cache_behavior["min_ttl"]
default_ttl = var.default_cache_behavior["default_ttl"]
max_ttl = var.default_cache_behavior["max_ttl"]
forwarded_values {
query_string = var.default_cache_behavior["forwarded_values"]["query_string"]
cookies {
forward = var.default_cache_behavior["forwarded_values"]["cookies"]["forward"]
}
}
}
origin {
domain_name = var.origin["domain_name"]
origin_id = var.origin["origin_id"]
custom_origin_config {
http_port = var.origin["custom_origin_config"]["http_port"]
https_port = var.origin["custom_origin_config"]["https_port"]
origin_protocol_policy = var.origin["custom_origin_config"]["origin_protocol_policy"]
origin_ssl_protocols = var.origin["custom_origin_config"]["origin_ssl_protocols"]
}
}
restrictions {
geo_restriction {
restriction_type = var.restrictions["geo_restriction"]["restriction_type"]
locations = var.restrictions["geo_restriction"]["locations"]
}
}
viewer_certificate {
cloudfront_default_certificate = var.viewer_certificate["cloudfront_default_certificate"]
acm_certificate_arn = var.viewer_certificate["acm_certificate_arn"]
ssl_support_method = var.viewer_certificate["ssl_support_method"]
minimum_protocol_version = var.viewer_certificate["minimum_protocol_version"]
}
}
data "aws_route53_zone" "hz" {
name = var.zone_domain_name
private_zone = false
}
data "aws_route53_zone" "hz_private" {
name = var.zone_domain_name_private
private_zone = true
}
resource "aws_route53_record" "hz" {
count = length(var.aliases)
zone_id = data.aws_route53_zone.hz.zone_id
name = var.aliases[count.index]
type = "A"
alias {
name = aws_cloudfront_distribution.cloudfront.domain_name
zone_id = aws_cloudfront_distribution.cloudfront.hosted_zone_id
evaluate_target_health = true
}
}
resource "aws_route53_record" "hz_private" {
count = length(var.aliases)
zone_id = data.aws_route53_zone.hz_private.zone_id
name = var.aliases[count.index]
type = "A"
alias {
name = aws_cloudfront_distribution.cloudfront.domain_name
zone_id = aws_cloudfront_distribution.cloudfront.hosted_zone_id
evaluate_target_health = true
}
}