opentofu-common/dns.tf
GregoryDosh daf26312d1
All checks were successful
Update Version / Update Version (push) Successful in 9s
feat: consistency sweeping w/ other repos to add release/tag process + license checking
2025-05-13 10:11:01 -05:00

49 lines
1.5 KiB
HCL

# git.auengun.net/homelab/opentofu-common
# Copyright (C) 2024 GregoryDosh
# SPDX-License-Identifier: AGPL-3.0-or-later
# SPDX-FileCopyrightText: 2024 GregoryDosh
variable "dns_split_horizon" {
type = bool
default = false
nullable = false
description = "If true, creates a DNS A record at the apex for a split-horizon networking setup."
}
locals {
reverse_lookup_zone = format("%s.%s", join(".", reverse(slice(split(".", var.internal_ipv4), 0, 3))), "in-addr.arpa.")
}
# DNS A Records
# https://registry.terraform.io/providers/hashicorp/dns/latest/docs/data-sources/a_record_set
resource "dns_a_record_set" "apex" {
zone = var.fqdn_apex
name = var.hostname
addresses = [
var.internal_ipv4
]
count = var.dns_split_horizon == true ? 1 : 0
}
# DNS A Records
# https://registry.terraform.io/providers/hashicorp/dns/latest/docs/data-sources/a_record_set
resource "dns_a_record_set" "subdomain" {
zone = var.fqdn_subdomain
name = var.hostname
addresses = [
var.internal_ipv4
]
}
# DNS PTR Records
# https://registry.terraform.io/providers/hashicorp/dns/latest/docs/resources/ptr_record
# This is so that I can do `nslookup <IP>` and remember which
# host is tied to which IP address. Also for logs/lookups elsewhere.
resource "dns_ptr_record" "reverse_ip_lookup" {
zone = local.reverse_lookup_zone
name = split(".", var.internal_ipv4)[3]
ptr = "${var.hostname}.${var.fqdn_subdomain}"
depends_on = [ dns_a_record_set.subdomain ]
}