Skip to content

Commit

Permalink
feat: Module now contains resources for private a, cname, txt and mx …
Browse files Browse the repository at this point in the history
…records
  • Loading branch information
habr-mms committed Sep 23, 2024
1 parent 7b6ae57 commit 8330923
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 2 deletions.
37 changes: 37 additions & 0 deletions examples/apply_main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,43 @@ module "dns" {
}
}
}
private_dns_a_record = {
"@" = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
records = ["127.0.0.3"]
}
}
private_dns_cname_record = {
www = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = module.dns.private_dns_a_record["@"].fqdn
}
}
private_dns_txt_record = {
dnsauth = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = {
frontdoor = {
value = "frontdoor"
}
}
}
}
private_dns_mx_record = {
mail = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = {
mail1 = {
preference = 10
exchange = "mail1.telekom-mms.com"
}
}
}
}
private_dns_zone_virtual_network_link = {
pl-mms-github = {
resource_group_name = "rg-mms-github"
Expand Down
61 changes: 61 additions & 0 deletions examples/full_main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,67 @@ module "dns" {
}
}
}
private_dns_a_record = {
"@" = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
records = ["127.0.0.3"]
tags = {
project = "mms-github"
environment = terraform.workspace
managed-by = "terraform"
}
}
}
private_dns_cname_record = {
www = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = module.dns.private_dns_a_record["@"].fqdn
tags = {
project = "mms-github"
environment = terraform.workspace
managed-by = "terraform"
}
}
}
private_dns_txt_record = {
dnsauth = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = {
frontdoor = {
value = "frontdoor"
}
}
tags = {
project = "mms-github"
environment = terraform.workspace
managed-by = "terraform"
}
}
}
private_dns_mx_record = {
mail = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = {
mail1 = {
preference = 10
exchange = "mail1.telekom-mms.com"
}
mail2 = {
preference = 20
exchange = "mail2.telekom-mms.com"
}
}
tags = {
project = "mms-github"
environment = terraform.workspace
managed-by = "terraform"
}
}
}
private_dns_zone_virtual_network_link = {
pl-mms-github = {
resource_group_name = "rg-mms-github"
Expand Down
37 changes: 37 additions & 0 deletions examples/min_main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,43 @@ module "dns" {
}
}
}
private_dns_a_record = {
"@" = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
records = ["127.0.0.3"]
}
}
private_dns_cname_record = {
www = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = module.dns.private_dns_a_record["@"].fqdn
}
}
private_dns_txt_record = {
dnsauth = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = {
frontdoor = {
value = "frontdoor"
}
}
}
}
private_dns_mx_record = {
mail = {
resource_group_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].resource_group_name
zone_name = module.dns.private_dns_zone["mms-github-privat-plattform.com"].name
record = {
mail1 = {
preference = 10
exchange = "mail1.telekom-mms.com"
}
}
}
}
private_dns_zone_virtual_network_link = {
pl-mms-github = {
resource_group_name = "rg-mms-github"
Expand Down
66 changes: 65 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* # dns
*
* This module manages the hashicorp/azurerm dns resources.
* This module manages the hashicorp/azurerm dns and private dns resources.
* For more information see https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs > dns
* and https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs > private dns
*
*/

Expand Down Expand Up @@ -69,6 +70,18 @@ resource "azurerm_dns_a_record" "dns_a_record" {
tags = local.dns_a_record[each.key].tags
}

resource "azurerm_private_dns_a_record" "private_dns_a_record" {
for_each = var.private_dns_a_record

name = local.private_dns_a_record[each.key].name == "" ? each.key : local.private_dns_a_record[each.key].name
resource_group_name = local.private_dns_a_record[each.key].resource_group_name
zone_name = local.private_dns_a_record[each.key].zone_name
ttl = local.private_dns_a_record[each.key].ttl
records = local.private_dns_a_record[each.key].records

tags = local.private_dns_a_record[each.key].tags
}

resource "azurerm_dns_cname_record" "dns_cname_record" {
for_each = var.dns_cname_record

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

resource "azurerm_private_dns_cname_record" "private_dns_cname_record" {
for_each = var.private_dns_cname_record

name = local.private_dns_cname_record[each.key].name == "" ? each.key : local.private_dns_cname_record[each.key].name
resource_group_name = local.private_dns_cname_record[each.key].resource_group_name
zone_name = local.private_dns_cname_record[each.key].zone_name
ttl = local.private_dns_cname_record[each.key].ttl
record = local.private_dns_cname_record[each.key].record

tags = local.private_dns_cname_record[each.key].tags
}

resource "azurerm_dns_txt_record" "dns_txt_record" {
for_each = var.dns_txt_record

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

resource "azurerm_private_dns_txt_record" "private_dns_txt_record" {
for_each = var.private_dns_txt_record

name = local.private_dns_txt_record[each.key].name == "" ? each.key : local.private_dns_txt_record[each.key].name
resource_group_name = local.private_dns_txt_record[each.key].resource_group_name
zone_name = local.private_dns_txt_record[each.key].zone_name
ttl = local.private_dns_txt_record[each.key].ttl

dynamic "record" {
for_each = local.private_dns_txt_record[each.key].record

content {
value = local.private_dns_txt_record[each.key].record[record.key].value
}
}

tags = local.private_dns_txt_record[each.key].tags
}

resource "azurerm_dns_mx_record" "dns_mx_record" {
for_each = var.dns_mx_record

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

resource "azurerm_private_dns_mx_record" "private_dns_mx_record" {
for_each = var.private_dns_mx_record

name = local.private_dns_mx_record[each.key].name == "" ? each.key : local.private_dns_mx_record[each.key].name
resource_group_name = local.private_dns_mx_record[each.key].resource_group_name
zone_name = local.private_dns_mx_record[each.key].zone_name
ttl = local.private_dns_mx_record[each.key].ttl

dynamic "record" {
for_each = local.private_dns_mx_record[each.key].record

content {
preference = local.private_dns_mx_record[each.key].record[record.key].preference
exchange = local.private_dns_mx_record[each.key].record[record.key].exchange
}
}

tags = local.private_dns_mx_record[each.key].tags
}

resource "azurerm_private_dns_zone_virtual_network_link" "private_dns_zone_virtual_network_link" {
for_each = var.private_dns_zone_virtual_network_link

Expand Down
41 changes: 40 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ output "dns_zone" {
}
}
}

output "private_dns_zone" {
description = "Outputs all attributes of resource_type."
value = {
Expand All @@ -30,6 +29,16 @@ output "dns_a_record" {
}
}
}
output "private_dns_a_record" {
description = "Outputs all attributes of resource_type."
value = {
for private_dns_a_record in keys(azurerm_private_dns_a_record.private_dns_a_record) :
private_dns_a_record => {
for key, value in azurerm_private_dns_a_record.private_dns_a_record[private_dns_a_record] :
key => value
}
}
}

output "dns_cname_record" {
description = "Outputs all attributes of resource_type."
Expand All @@ -41,6 +50,16 @@ output "dns_cname_record" {
}
}
}
output "private_dns_cname_record" {
description = "Outputs all attributes of resource_type."
value = {
for private_dns_cname_record in keys(azurerm_private_dns_cname_record.private_dns_cname_record) :
private_dns_cname_record => {
for key, value in azurerm_private_dns_cname_record.private_dns_cname_record[private_dns_cname_record] :
key => value
}
}
}

output "dns_txt_record" {
description = "Outputs all attributes of resource_type."
Expand All @@ -52,6 +71,16 @@ output "dns_txt_record" {
}
}
}
output "private_dns_txt_record" {
description = "Outputs all attributes of resource_type."
value = {
for private_dns_txt_record in keys(azurerm_private_dns_txt_record.private_dns_txt_record) :
private_dns_txt_record => {
for key, value in azurerm_private_dns_txt_record.private_dns_txt_record[private_dns_txt_record] :
key => value
}
}
}

output "dns_mx_record" {
description = "Outputs all attributes of resource_type."
Expand All @@ -63,6 +92,16 @@ output "dns_mx_record" {
}
}
}
output "private_dns_mx_record" {
description = "Outputs all attributes of resource_type."
value = {
for private_dns_mx_record in keys(azurerm_private_dns_mx_record.private_dns_mx_record) :
private_dns_mx_record => {
for key, value in azurerm_private_dns_mx_record.private_dns_mx_record[private_dns_mx_record] :
key => value
}
}
}

output "private_dns_zone_virtual_network_link" {
description = "Outputs all attributes of resource_type."
Expand Down
Loading

0 comments on commit 8330923

Please sign in to comment.