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" {} data "cloudflare_accounts" "default" {}
# output "accounts" { locals {
# value = data.cloudflare_accounts.default.accounts[0] 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" { resource "cloudflare_zone" "balsillie_net" {
account_id = data.cloudflare_accounts.default.accounts[0].id 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 zone_id = cloudflare_zone.balsillie_net.id
} }
resource "cloudflare_record" "a_records" { resource "cloudflare_record" "dns_records" {
for_each = var.a_records for_each = local.dns_records
zone_id = cloudflare_zone.balsillie_net.id zone_id = cloudflare_zone.balsillie_net.id
proxied = false proxied = false
type = "A" name = each.value.name
ttl = 60 type = each.value.type
name = each.key content = each.value.content
content = each.value ttl = each.value.ttl
} }
resource "cloudflare_record" "cname_records" { # TODO update the SOA record when dns_records resource was changed
for_each = var.cname_records
zone_id = cloudflare_zone.balsillie_net.id
proxied = false
type = "CNAME"
ttl = 60
name = each.key
content = each.value
}

View File

@ -5,20 +5,13 @@ variable "api_token" {
sensitive = true sensitive = true
} }
variable "a_records" { variable "dns_records" {
description = "DNS A records to create" description = "DNS A records to create"
type = map(string) type = list(object({
default = {} 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 = { dns_records = [
a = "5.161.254.39", { 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 },
a_records = { { name = "hetzner", type = "A", content = "5.161.254.39", ttl = 60 },
www = "5.161.254.39" { name = "imap", type = "A", content = "5.161.254.39", ttl = 60 },
cloud = "5.161.254.39" { name = "sieve", type = "A", content = "5.161.254.39", ttl = 60 },
cloud = "5.161.254.39" { name = "smtp", type = "A", content = "5.161.254.39", ttl = 60 },
hetzner = "5.161.254.39" { name = "auth", type = "CNAME", content = "hetzner", ttl = 60 },
imap = "5.161.254.39" { name = "autoconfig", type = "CNAME", content = "hetzner", ttl = 60 },
sieve = "5.161.254.39" { name = "autodiscover", type = "CNAME", content = "hetzner", ttl = 60 },
smtp = "5.161.254.39" { 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 },
# test comment { name = "matrix", type = "CNAME", content = "hetzner", ttl = 60 },
{ name = "matrix-auth", type = "CNAME", content = "hetzner", ttl = 60 },
cname_records = { { name = "matrix-federation", type = "CNAME", content = "hetzner", ttl = 60 },
auth = "hetzner" { name = "matrix-sync", type = "CNAME", content = "hetzner", ttl = 60 },
autoconfig = "hetzner" { name = "mta-sts", type = "CNAME", content = "hetzner", ttl = 60 },
autodiscover = "hetzner" { name = "notify", type = "CNAME", content = "hetzner", ttl = 60 },
code = "hetzner" { name = "office", type = "CNAME", content = "hetzner", ttl = 60 },
discord-bridge = "hetzner" { name = "signal-bridge", type = "CNAME", content = "hetzner", ttl = 60 },
im = "hetzner" { name = "social", type = "CNAME", content = "hetzner", ttl = 60 },
matrix = "hetzner" { name = "turn", type = "CNAME", content = "hetzner", ttl = 60 },
matrix-auth = "hetzner" { name = "whatsapp-bridge", type = "CNAME", content = "hetzner", ttl = 60 }
matrix-federation = "hetzner" ]
matrix-sync = "hetzner"
mta-sts = "hetzner"
notify = "hetzner"
office = "hetzner"
signal-bridge = "hetzner"
social = "hetzner"
turn = "hetzner"
whatsapp-bridge = "hetzner"
}