From f8fdea29758ee2edfd62b5c8663e81e93e837a8c Mon Sep 17 00:00:00 2001 From: Otho Ulrich Date: Sun, 1 Jan 2023 00:26:38 -0500 Subject: [PATCH] Improved terraform formatting and update ALIAS. --- dns.tf | 87 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/dns.tf b/dns.tf index b068c37..f4b9d0a 100644 --- a/dns.tf +++ b/dns.tf @@ -18,115 +18,106 @@ terraform { provider "namecheap" {} +variable "apex-domain" { + type = string + default = "othoulrich.com." +} + +variable "host-rproxy" { + type = string + default = "rprxy-0.saline.o4data.net." +} + variable "protonmail-domainkey-id" { type = string default = "dr2jx5mioyzdmwndxrlrsgzx3nne5vtshiheypfxy7llz4e2hwrcq" } -locals { - address = { - cname = { - "www" = "othoulrich.com." - "code" = "othoulrich.com." - "protonmail._domainkey" = join(".",[ - "protonmail.domainkey", - var.protonmail-domainkey-id, - "domains.proton.ch." - ]) - "protonmail2._domainkey" = join(".",[ - "protonmail2.domainkey", - var.protonmail-domainkey-id, - "domains.proton.ch." - ]) - "protonmail3._domainkey" = join(".",[ - "protonmail3.domainkey", - var.protonmail-domainkey-id, - "domains.proton.ch." - ]) - } - txt = { - "@.0" = join("=",[ - "protonmail-verification", - "6568aab64dccc1e888741cf9874730f7fc884a00" - ]) - "@.1" = "v=spf1 include:_spf.protonmail.ch mx ~all" - } - mx = { - "@.0" = "mail.protonmail.ch." - "@.1" = "mailsec.protonmail.ch." - } - alias = { - "@.0" = "fw-0.saline.o4data.net." - } - } +variable "protonmail-verification-key" { + type = string + default = "6568aab64dccc1e888741cf9874730f7fc884a00" } resource "namecheap_domain_records" "top" { - domain = "othoulrich.com" + domain = trim(var.apex-domain,".") mode = "OVERWRITE" email_type = "MX" record { - address = local.address.alias["@.0"] hostname = "@" + address = var.host-rproxy type = "ALIAS" ttl = 300 } record { - address = local.address.cname["www"] hostname = "www" + address = var.apex-domain type = "CNAME" } record { - address = local.address.cname["code"] hostname = "code" + address = var.apex-domain type = "CNAME" } record { - address = local.address.mx["@.0"] hostname = "@" + address = "mail.protonmail.ch." type = "MX" } record { - address = local.address.mx["@.1"] hostname = "@" + address = "mailsec.protonmail.ch." mx_pref = 20 type = "MX" } record { - address = local.address.txt["@.0"] hostname = "@" + address = join("=",[ + "protonmail-verification", + var.protonmail-verification-key + ]) type = "TXT" } record { - address = local.address.txt["@.1"] hostname = "@" + address = "v=spf1 include:_spf.protonmail.ch mx ~all" type = "TXT" } record { - address = local.address.cname["protonmail._domainkey"] hostname = "protonmail._domainkey" + address = join(".",[ + "protonmail.domainkey", + var.protonmail-domainkey-id, + "domains.proton.ch." + ]) type = "CNAME" } record { - address = local.address.cname["protonmail2._domainkey"] hostname = "protonmail2._domainkey" + address = join(".",[ + "protonmail2.domainkey", + var.protonmail-domainkey-id, + "domains.proton.ch." + ]) type = "CNAME" } record { - address = local.address.cname["protonmail3._domainkey"] hostname = "protonmail3._domainkey" + address = join(".",[ + "protonmail3.domainkey", + var.protonmail-domainkey-id, + "domains.proton.ch." + ]) type = "CNAME" } - }