generated from dxw/terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute53-custom-hosted-zones.tf
115 lines (83 loc) · 2.88 KB
/
route53-custom-hosted-zones.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
resource "aws_route53_zone" "custom" {
for_each = local.custom_route53_hosted_zones
name = each.key
comment = "${local.resource_prefix} ${each.key}"
lifecycle {
prevent_destroy = true
}
}
resource "aws_route53_record" "custom_ns" {
for_each = merge([
for k, v in local.custom_route53_hosted_zones : {
for ns_name, ns_record in v["ns_records"] : "${k}_${ns_name}" => merge(ns_record, { zone_name = k, name = ns_name })
}
]...)
name = each.value["name"]
type = "NS"
ttl = each.value["ttl"]
zone_id = aws_route53_zone.custom[each.value["zone_name"]].zone_id
records = each.value["values"]
}
resource "aws_route53_record" "custom_a" {
for_each = merge([
for k, v in local.custom_route53_hosted_zones : {
for a_name, a_record in v["a_records"] : "${k}_${a_name}" => merge(a_record, { zone_name = k, name = a_name })
}
]...)
name = each.value["name"]
type = "A"
ttl = each.value["ttl"]
zone_id = aws_route53_zone.custom[each.value["zone_name"]].zone_id
records = each.value["values"]
}
resource "aws_route53_record" "custom_alias" {
for_each = merge([
for k, v in local.custom_route53_hosted_zones : {
for alias_name, alias_records in v["alias_records"] : "${k}_${alias_name}" => merge(alias_records, { zone_name = k, name = alias_name })
}
]...)
name = each.value["name"]
type = "A"
zone_id = aws_route53_zone.custom[each.value["zone_name"]].zone_id
alias {
name = each.value["value"]
zone_id = each.value["zone_id"]
evaluate_target_health = false
}
}
resource "aws_route53_record" "custom_cname" {
for_each = merge([
for k, v in local.custom_route53_hosted_zones : {
for cname_name, cname_record in v["cname_records"] : "${k}_${cname_name}" => merge(cname_record, { zone_name = k, name = cname_name })
}
]...)
name = each.value["name"]
type = "CNAME"
ttl = each.value["ttl"]
zone_id = aws_route53_zone.custom[each.value["zone_name"]].zone_id
records = each.value["values"]
}
resource "aws_route53_record" "custom_mx" {
for_each = merge([
for k, v in local.custom_route53_hosted_zones : {
for mx_name, mx_record in v["mx_records"] : "${k}_${mx_name}" => merge(mx_record, { zone_name = k, name = mx_name })
}
]...)
name = each.value["name"]
type = "MX"
ttl = each.value["ttl"]
zone_id = aws_route53_zone.custom[each.value["zone_name"]].zone_id
records = each.value["values"]
}
resource "aws_route53_record" "custom_txt" {
for_each = merge([
for k, v in local.custom_route53_hosted_zones : {
for txt_name, txt_record in v["txt_records"] : "${k}_${txt_name}" => merge(txt_record, { zone_name = k, name = txt_name })
}
]...)
name = each.value["name"]
type = "TXT"
ttl = each.value["ttl"]
zone_id = aws_route53_zone.custom[each.value["zone_name"]].zone_id
records = each.value["values"]
}