forked from cytopia/terraform-aws-route53-zone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
97 lines (74 loc) · 2.99 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
# -------------------------------------------------------------------------------------------------
# Delegation sets
# -------------------------------------------------------------------------------------------------
resource "aws_route53_delegation_set" "delegation_sets" {
for_each = { for val in var.delegation_sets : val => val }
reference_name = each.value
}
# -------------------------------------------------------------------------------------------------
# Public root zones
# -------------------------------------------------------------------------------------------------
resource "aws_route53_zone" "public_root_zones" {
for_each = local.public_root_zones
name = each.value.name
comment = var.comment
delegation_set_id = each.value.deleg_id
tags = merge(
map("Name", each.value.name),
map("DelegationSetId", each.value.deleg_id),
map("DelegationSetName", each.value.deleg_name),
var.tags
)
depends_on = [aws_route53_delegation_set.delegation_sets]
}
# -------------------------------------------------------------------------------------------------
# Public secondary zones
# -------------------------------------------------------------------------------------------------
resource "aws_route53_zone" "public_delegated_secondary_zones" {
for_each = local.public_delegated_secondary_zones
name = each.value.name
comment = var.comment
delegation_set_id = each.value.deleg_id
tags = merge(
map("Name", each.value.name),
map("Parent", each.value.parent),
map("DelegationSetId", each.value.deleg_id),
map("DelegationSetName", each.value.deleg_name),
var.tags
)
depends_on = [aws_route53_zone.public_root_zones]
}
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone#public-subdomain-zone
resource "aws_route53_record" "public_delegated_secondary_ns_records" {
for_each = local.public_delegated_secondary_ns_records
zone_id = aws_route53_zone.public_root_zones[each.value.parent]["id"]
name = each.value.name
type = "NS"
ttl = each.value.ns_ttl
records = formatlist("%s.", each.value.ns_list)
depends_on = [aws_route53_zone.public_delegated_secondary_zones]
}
# -------------------------------------------------------------------------------------------------
# Private root zones
# -------------------------------------------------------------------------------------------------
data "aws_vpc" "default" {
default = true
}
data "aws_region" "current" {}
resource "aws_route53_zone" "private_root_zones" {
for_each = local.private_root_zones
name = each.value.name
comment = var.comment
dynamic "vpc" {
for_each = { for vpc in concat([{ "id" = data.aws_vpc.default.id, "region" = data.aws_region.current.name }], each.value.vpc_ids) : vpc.id => vpc }
content {
vpc_id = vpc.value.id
vpc_region = vpc.value.region
}
}
tags = merge(
map("Name", each.value.name),
var.tags
)
depends_on = [data.aws_vpc.default, data.aws_region.current]
}