-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.tf
59 lines (50 loc) · 2.08 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
locals {
enabled = module.this.enabled ? 1 : 0
parent_zone_record_enabled = var.parent_zone_record_enabled && module.this.enabled ? 1 : 0
zone_name = local.parent_zone_record_enabled == 1 ? var.zone_name : replace(var.zone_name, ".$${parent_zone_name}", "")
}
data "aws_region" "default" {}
data "aws_route53_zone" "parent_zone" {
count = local.parent_zone_record_enabled
zone_id = var.parent_zone_id
name = var.parent_zone_name
}
resource "aws_route53_zone" "default" {
count = local.enabled
# https://github.com/hashicorp/terraform/issues/26838#issuecomment-840022506
name = replace(replace(replace(replace(replace(replace(replace(replace(replace(local.zone_name,
"$${namespace}", module.this.namespace),
"$${tenant}", module.this.tenant),
"$${environment}", module.this.environment),
"$${name}", module.this.name),
"$${stage}", module.this.stage),
"$${id}", module.this.id),
"$${attributes}", join(module.this.delimiter, module.this.attributes)),
"$${parent_zone_name}", coalesce(join("", data.aws_route53_zone.parent_zone.*.name), var.parent_zone_name, "none")),
"$${region}", data.aws_region.default.name)
tags = module.this.tags
}
resource "aws_route53_record" "ns" {
count = local.parent_zone_record_enabled
zone_id = join("", data.aws_route53_zone.parent_zone.*.zone_id)
name = join("", aws_route53_zone.default.*.name)
type = "NS"
ttl = var.ns_record_ttl
records = [
aws_route53_zone.default[0].name_servers[0],
aws_route53_zone.default[0].name_servers[1],
aws_route53_zone.default[0].name_servers[2],
aws_route53_zone.default[0].name_servers[3],
]
}
resource "aws_route53_record" "soa" {
count = local.enabled
allow_overwrite = true
zone_id = join("", aws_route53_zone.default.*.id)
name = join("", aws_route53_zone.default.*.name)
type = "SOA"
ttl = var.soa_record_ttl
records = [
format("%s. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400", aws_route53_zone.default[0].name_servers[0])
]
}