-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns.tf
60 lines (54 loc) · 1.89 KB
/
dns.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
#------------------------------
# DNS
#------------------------------
# Create AWS Route 53 records if local.gandi_zone is false
resource "aws_route53_record" "site" {
count = local.gandi_zone == true ? 0 : 1
zone_id = var.route53_zone_id
name = var.website_hostname
type = "A"
alias {
name = aws_cloudfront_distribution.site.domain_name
zone_id = aws_cloudfront_distribution.site.hosted_zone_id
evaluate_target_health = false
}
}
resource "aws_route53_record" "site-validation" {
for_each = {
for option in aws_acm_certificate.site.domain_validation_options : option.domain_name => {
name = option.resource_record_name
record = option.resource_record_value
type = option.resource_record_type
} if local.gandi_zone == false
}
allow_overwrite = true
name = each.value.name
records = [each.value.record]
type = each.value.type
zone_id = var.route53_zone_id
ttl = 60
}
# Create Gandi LiveDNS records if local.gandi_zone is true
resource "gandi_livedns_record" "site" {
count = local.gandi_zone == true ? 1 : 0
name = local.hostname # Gandi doesn't store records fully qualified
zone = local.domain
type = "CNAME"
ttl = 600
values = ["${aws_cloudfront_distribution.site.domain_name}."]
}
resource "gandi_livedns_record" "site-validation" {
for_each = {
for option in aws_acm_certificate.site.domain_validation_options : option.domain_name => {
name = option.resource_record_name
record = option.resource_record_value
type = option.resource_record_type
} if local.gandi_zone == true
}
# Gandi doesn't store the records fully qualified so we trim the domain off
name = trimsuffix(each.value.name, ".${local.domain}.")
zone = local.domain
ttl = 600
type = each.value.type
values = [each.value.record]
}