Skip to content

Commit 33c79d0

Browse files
authored
Merge pull request #26 from telekom-mms/feat/more_private_dns_resources
More private dns resources
2 parents 7b6ae57 + 8330923 commit 33c79d0

6 files changed

Lines changed: 298 additions & 2 deletions

File tree

examples/apply_main.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,43 @@ module "dns" {
5858
}
5959
}
6060
}
61+
private_dns_a_record = {
62+
"@" = {
63+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
64+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
65+
records = ["127.0.0.3"]
66+
}
67+
}
68+
private_dns_cname_record = {
69+
www = {
70+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
71+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
72+
record = module.dns.private_dns_a_record["@"].fqdn
73+
}
74+
}
75+
private_dns_txt_record = {
76+
dnsauth = {
77+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
78+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
79+
record = {
80+
frontdoor = {
81+
value = "frontdoor"
82+
}
83+
}
84+
}
85+
}
86+
private_dns_mx_record = {
87+
mail = {
88+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
89+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
90+
record = {
91+
mail1 = {
92+
preference = 10
93+
exchange = "mail1.telekom-mms.com"
94+
}
95+
}
96+
}
97+
}
6198
private_dns_zone_virtual_network_link = {
6299
pl-mms-github = {
63100
resource_group_name = "rg-mms-github"

examples/full_main.tf

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,67 @@ module "dns" {
9898
}
9999
}
100100
}
101+
private_dns_a_record = {
102+
"@" = {
103+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
104+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
105+
records = ["127.0.0.3"]
106+
tags = {
107+
project = "mms-github"
108+
environment = terraform.workspace
109+
managed-by = "terraform"
110+
}
111+
}
112+
}
113+
private_dns_cname_record = {
114+
www = {
115+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
116+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
117+
record = module.dns.private_dns_a_record["@"].fqdn
118+
tags = {
119+
project = "mms-github"
120+
environment = terraform.workspace
121+
managed-by = "terraform"
122+
}
123+
}
124+
}
125+
private_dns_txt_record = {
126+
dnsauth = {
127+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
128+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
129+
record = {
130+
frontdoor = {
131+
value = "frontdoor"
132+
}
133+
}
134+
tags = {
135+
project = "mms-github"
136+
environment = terraform.workspace
137+
managed-by = "terraform"
138+
}
139+
}
140+
}
141+
private_dns_mx_record = {
142+
mail = {
143+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
144+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
145+
record = {
146+
mail1 = {
147+
preference = 10
148+
exchange = "mail1.telekom-mms.com"
149+
}
150+
mail2 = {
151+
preference = 20
152+
exchange = "mail2.telekom-mms.com"
153+
}
154+
}
155+
tags = {
156+
project = "mms-github"
157+
environment = terraform.workspace
158+
managed-by = "terraform"
159+
}
160+
}
161+
}
101162
private_dns_zone_virtual_network_link = {
102163
pl-mms-github = {
103164
resource_group_name = "rg-mms-github"

examples/min_main.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,43 @@ module "dns" {
5858
}
5959
}
6060
}
61+
private_dns_a_record = {
62+
"@" = {
63+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
64+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
65+
records = ["127.0.0.3"]
66+
}
67+
}
68+
private_dns_cname_record = {
69+
www = {
70+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
71+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
72+
record = module.dns.private_dns_a_record["@"].fqdn
73+
}
74+
}
75+
private_dns_txt_record = {
76+
dnsauth = {
77+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
78+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
79+
record = {
80+
frontdoor = {
81+
value = "frontdoor"
82+
}
83+
}
84+
}
85+
}
86+
private_dns_mx_record = {
87+
mail = {
88+
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
89+
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
90+
record = {
91+
mail1 = {
92+
preference = 10
93+
exchange = "mail1.telekom-mms.com"
94+
}
95+
}
96+
}
97+
}
6198
private_dns_zone_virtual_network_link = {
6299
pl-mms-github = {
63100
resource_group_name = "rg-mms-github"

main.tf

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
22
* # dns
33
*
4-
* This module manages the hashicorp/azurerm dns resources.
4+
* This module manages the hashicorp/azurerm dns and private dns resources.
55
* For more information see https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs > dns
6+
* and https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs > private dns
67
*
78
*/
89

@@ -69,6 +70,18 @@ resource "azurerm_dns_a_record" "dns_a_record" {
6970
tags = local.dns_a_record[each.key].tags
7071
}
7172

73+
resource "azurerm_private_dns_a_record" "private_dns_a_record" {
74+
for_each = var.private_dns_a_record
75+
76+
name = local.private_dns_a_record[each.key].name == "" ? each.key : local.private_dns_a_record[each.key].name
77+
resource_group_name = local.private_dns_a_record[each.key].resource_group_name
78+
zone_name = local.private_dns_a_record[each.key].zone_name
79+
ttl = local.private_dns_a_record[each.key].ttl
80+
records = local.private_dns_a_record[each.key].records
81+
82+
tags = local.private_dns_a_record[each.key].tags
83+
}
84+
7285
resource "azurerm_dns_cname_record" "dns_cname_record" {
7386
for_each = var.dns_cname_record
7487

@@ -82,6 +95,18 @@ resource "azurerm_dns_cname_record" "dns_cname_record" {
8295
tags = local.dns_cname_record[each.key].tags
8396
}
8497

98+
resource "azurerm_private_dns_cname_record" "private_dns_cname_record" {
99+
for_each = var.private_dns_cname_record
100+
101+
name = local.private_dns_cname_record[each.key].name == "" ? each.key : local.private_dns_cname_record[each.key].name
102+
resource_group_name = local.private_dns_cname_record[each.key].resource_group_name
103+
zone_name = local.private_dns_cname_record[each.key].zone_name
104+
ttl = local.private_dns_cname_record[each.key].ttl
105+
record = local.private_dns_cname_record[each.key].record
106+
107+
tags = local.private_dns_cname_record[each.key].tags
108+
}
109+
85110
resource "azurerm_dns_txt_record" "dns_txt_record" {
86111
for_each = var.dns_txt_record
87112

@@ -101,6 +126,25 @@ resource "azurerm_dns_txt_record" "dns_txt_record" {
101126
tags = local.dns_txt_record[each.key].tags
102127
}
103128

129+
resource "azurerm_private_dns_txt_record" "private_dns_txt_record" {
130+
for_each = var.private_dns_txt_record
131+
132+
name = local.private_dns_txt_record[each.key].name == "" ? each.key : local.private_dns_txt_record[each.key].name
133+
resource_group_name = local.private_dns_txt_record[each.key].resource_group_name
134+
zone_name = local.private_dns_txt_record[each.key].zone_name
135+
ttl = local.private_dns_txt_record[each.key].ttl
136+
137+
dynamic "record" {
138+
for_each = local.private_dns_txt_record[each.key].record
139+
140+
content {
141+
value = local.private_dns_txt_record[each.key].record[record.key].value
142+
}
143+
}
144+
145+
tags = local.private_dns_txt_record[each.key].tags
146+
}
147+
104148
resource "azurerm_dns_mx_record" "dns_mx_record" {
105149
for_each = var.dns_mx_record
106150

@@ -121,6 +165,26 @@ resource "azurerm_dns_mx_record" "dns_mx_record" {
121165
tags = local.dns_mx_record[each.key].tags
122166
}
123167

168+
resource "azurerm_private_dns_mx_record" "private_dns_mx_record" {
169+
for_each = var.private_dns_mx_record
170+
171+
name = local.private_dns_mx_record[each.key].name == "" ? each.key : local.private_dns_mx_record[each.key].name
172+
resource_group_name = local.private_dns_mx_record[each.key].resource_group_name
173+
zone_name = local.private_dns_mx_record[each.key].zone_name
174+
ttl = local.private_dns_mx_record[each.key].ttl
175+
176+
dynamic "record" {
177+
for_each = local.private_dns_mx_record[each.key].record
178+
179+
content {
180+
preference = local.private_dns_mx_record[each.key].record[record.key].preference
181+
exchange = local.private_dns_mx_record[each.key].record[record.key].exchange
182+
}
183+
}
184+
185+
tags = local.private_dns_mx_record[each.key].tags
186+
}
187+
124188
resource "azurerm_private_dns_zone_virtual_network_link" "private_dns_zone_virtual_network_link" {
125189
for_each = var.private_dns_zone_virtual_network_link
126190

outputs.tf

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ output "dns_zone" {
88
}
99
}
1010
}
11-
1211
output "private_dns_zone" {
1312
description = "Outputs all attributes of resource_type."
1413
value = {
@@ -30,6 +29,16 @@ output "dns_a_record" {
3029
}
3130
}
3231
}
32+
output "private_dns_a_record" {
33+
description = "Outputs all attributes of resource_type."
34+
value = {
35+
for private_dns_a_record in keys(azurerm_private_dns_a_record.private_dns_a_record) :
36+
private_dns_a_record => {
37+
for key, value in azurerm_private_dns_a_record.private_dns_a_record[private_dns_a_record] :
38+
key => value
39+
}
40+
}
41+
}
3342

3443
output "dns_cname_record" {
3544
description = "Outputs all attributes of resource_type."
@@ -41,6 +50,16 @@ output "dns_cname_record" {
4150
}
4251
}
4352
}
53+
output "private_dns_cname_record" {
54+
description = "Outputs all attributes of resource_type."
55+
value = {
56+
for private_dns_cname_record in keys(azurerm_private_dns_cname_record.private_dns_cname_record) :
57+
private_dns_cname_record => {
58+
for key, value in azurerm_private_dns_cname_record.private_dns_cname_record[private_dns_cname_record] :
59+
key => value
60+
}
61+
}
62+
}
4463

4564
output "dns_txt_record" {
4665
description = "Outputs all attributes of resource_type."
@@ -52,6 +71,16 @@ output "dns_txt_record" {
5271
}
5372
}
5473
}
74+
output "private_dns_txt_record" {
75+
description = "Outputs all attributes of resource_type."
76+
value = {
77+
for private_dns_txt_record in keys(azurerm_private_dns_txt_record.private_dns_txt_record) :
78+
private_dns_txt_record => {
79+
for key, value in azurerm_private_dns_txt_record.private_dns_txt_record[private_dns_txt_record] :
80+
key => value
81+
}
82+
}
83+
}
5584

5685
output "dns_mx_record" {
5786
description = "Outputs all attributes of resource_type."
@@ -63,6 +92,16 @@ output "dns_mx_record" {
6392
}
6493
}
6594
}
95+
output "private_dns_mx_record" {
96+
description = "Outputs all attributes of resource_type."
97+
value = {
98+
for private_dns_mx_record in keys(azurerm_private_dns_mx_record.private_dns_mx_record) :
99+
private_dns_mx_record => {
100+
for key, value in azurerm_private_dns_mx_record.private_dns_mx_record[private_dns_mx_record] :
101+
key => value
102+
}
103+
}
104+
}
66105

67106
output "private_dns_zone_virtual_network_link" {
68107
description = "Outputs all attributes of resource_type."

0 commit comments

Comments
 (0)