1
0

tf dns wip

This commit is contained in:
= 2024-10-26 16:48:20 +13:00
parent 9464737fe9
commit 29cb12a2d1
3 changed files with 49 additions and 70 deletions

View File

@ -18,9 +18,12 @@ provider "cloudflare" {
data "cloudflare_accounts" "default" {}
# output "accounts" {
# value = data.cloudflare_accounts.default.accounts[0]
# }
locals {
dns_records = {
for index, record in distinct(var.dns_records) : # 'distint' removes duplicate values from a list
tostring(index) => record
}
}
resource "cloudflare_zone" "balsillie_net" {
account_id = data.cloudflare_accounts.default.accounts[0].id
@ -34,22 +37,14 @@ resource "cloudflare_zone_dnssec" "balsillie_net" {
zone_id = cloudflare_zone.balsillie_net.id
}
resource "cloudflare_record" "a_records" {
for_each = var.a_records
zone_id = cloudflare_zone.balsillie_net.id
proxied = false
type = "A"
ttl = 60
name = each.key
content = each.value
resource "cloudflare_record" "dns_records" {
for_each = local.dns_records
zone_id = cloudflare_zone.balsillie_net.id
proxied = false
name = each.value.name
type = each.value.type
content = each.value.content
ttl = each.value.ttl
}
resource "cloudflare_record" "cname_records" {
for_each = var.cname_records
zone_id = cloudflare_zone.balsillie_net.id
proxied = false
type = "CNAME"
ttl = 60
name = each.key
content = each.value
}
# TODO update the SOA record when dns_records resource was changed

View File

@ -5,20 +5,13 @@ variable "api_token" {
sensitive = true
}
variable "a_records" {
variable "dns_records" {
description = "DNS A records to create"
type = map(string)
default = {}
type = list(object({
name = string
type = string
content = string
ttl = number
}))
default = []
}
variable "cname_records" {
description = "DNS CNAME records to create"
type = map(string)
default = {}
}
variable "root_records" {
description = "Special root records to create with name @"
type = map(string)
default = {}
}

View File

@ -1,35 +1,26 @@
root_records = {
a = "5.161.254.39",
}
a_records = {
www = "5.161.254.39"
cloud = "5.161.254.39"
cloud = "5.161.254.39"
hetzner = "5.161.254.39"
imap = "5.161.254.39"
sieve = "5.161.254.39"
smtp = "5.161.254.39"
}
# test comment
cname_records = {
auth = "hetzner"
autoconfig = "hetzner"
autodiscover = "hetzner"
code = "hetzner"
discord-bridge = "hetzner"
im = "hetzner"
matrix = "hetzner"
matrix-auth = "hetzner"
matrix-federation = "hetzner"
matrix-sync = "hetzner"
mta-sts = "hetzner"
notify = "hetzner"
office = "hetzner"
signal-bridge = "hetzner"
social = "hetzner"
turn = "hetzner"
whatsapp-bridge = "hetzner"
}
dns_records = [
{ name = "@", type = "A", content = "5.161.254.39", ttl = 60 },
{ name = "www", type = "A", content = "5.161.254.39", ttl = 60 },
{ name = "cloud", type = "A", content = "5.161.254.39", ttl = 60 },
{ name = "hetzner", type = "A", content = "5.161.254.39", ttl = 60 },
{ name = "imap", type = "A", content = "5.161.254.39", ttl = 60 },
{ name = "sieve", type = "A", content = "5.161.254.39", ttl = 60 },
{ name = "smtp", type = "A", content = "5.161.254.39", ttl = 60 },
{ name = "auth", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "autoconfig", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "autodiscover", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "code", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "discord-bridge", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "im", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "matrix", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "matrix-auth", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "matrix-federation", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "matrix-sync", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "mta-sts", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "notify", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "office", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "signal-bridge", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "social", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "turn", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "whatsapp-bridge", type = "CNAME", content = "hetzner", ttl = 60 }
]