This repository has been archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudfront.jp.example.tf
103 lines (83 loc) · 3.19 KB
/
cloudfront.jp.example.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
# --------------------------------
# CloudFront: example.jp
resource "aws_cloudfront_distribution" "distribution_jp_example" {
count = "${length(var.envs)}"
# WAF:
# Enabled if environments are:
# - `external` => disabled (blank)
# - `internal` or `review` => enabled
web_acl_id = "${element(var.envs, count.index) == var.default_env_name ? "" : aws_waf_web_acl.website-waf-web-acl.id}"
enabled = true
is_ipv6_enabled = true
default_root_object = "index.html"
price_class = "PriceClass_200"
origin {
domain_name = "${element(aws_s3_bucket.website-content.*.bucket_regional_domain_name, count.index)}"
origin_id = "${element(var.envs, count.index)}-${var.service_name}-origin_id"
s3_origin_config {
origin_access_identity = "${element(aws_cloudfront_origin_access_identity.website-origin_access_identities.*.cloudfront_access_identity_path, count.index)}"
}
}
logging_config {
include_cookies = false
bucket = "${element(aws_s3_bucket.website-log.*.bucket_domain_name, count.index)}"
prefix = "${element(var.envs, count.index)}-${var.service_name}/"
}
aliases = [
"${element(var.envs, count.index) == var.default_env_name ? "" : format("%s.", element(var.envs, count.index))}example.jp",
]
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "${element(var.envs, count.index)}-${var.service_name}-origin_id"
compress = true
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
lambda_function_association = [
{
event_type = "viewer-request"
lambda_arn = "${aws_lambda_function.website-lambda-redirect-to-index-document.qualified_arn}"
},
]
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = "${aws_acm_certificate.certificate_jp_example_.arn}"
ssl_support_method = "sni-only"
}
tags = {}
}
# --------------------------------
# Route 53 record: example.jp
resource "aws_route53_record" "records_jp_example_" {
count = "${length(var.envs)}"
zone_id = "${aws_route53_zone.zone_jp_example.zone_id}"
# ToDo: remove `temporary.`$
name = "${element(var.envs, count.index) == var.default_env_name ? "temporary." : format("%s.", element(var.envs, count.index))}example.jp"
type = "A"
alias {
name = "${element(aws_cloudfront_distribution.distribution_jp_example.*.domain_name, count.index)}"
zone_id = "${element(aws_cloudfront_distribution.distribution_jp_example.*.hosted_zone_id, count.index)}"
evaluate_target_health = false
}
}
# --------------------------------
# Outputs
output "website-content::distribution_jp_example::domain_names" {
value = ["${aws_cloudfront_distribution.distribution_jp_example.*.domain_name}"]
}
output "website-content::records_jp_example_::names" {
value = ["${aws_route53_record.records_jp_example_.*.name}"]
}