diff --git a/GNUmakefile b/GNUmakefile index a9115aa..de3aa4a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -26,19 +26,24 @@ attic: install -dm755 $@ .PHONY: backup -backup: backup-history backup-ssl backup-gitea +backup: backup-history backup-ssl backup-gitea backup-syncthing .PHONY: backup-history backup-history: attic -$(SSH) $(SSH_OPTS) root@`$(TF) output ipv4` 'cat /root/.ash_history' > attic/.ash_history.$(RUN_EPOCH) - [ -z attic/.ash_history.$(RUN_EPOCH) ] && rm attic/.ash_history.$(RUN_EPOCH) || ln -sf attic/.ash_history.$(RUN_EPOCH) attic/.ash_history + [ -z attic/.ash_history.$(RUN_EPOCH) ] && rm attic/.ash_history.$(RUN_EPOCH) || ln -f attic/.ash_history.$(RUN_EPOCH) attic/.ash_history .PHONY: backup-gitea backup-gitea: attic - $(SSH) $(SSH_OPTS) root@`$(TF) output ipv4` 'tar cvf - /var/lib/gitea /etc/gitea' > /attic/var-lib-gitea.tar.$(RUN_EPOCH) - ln -sf attic/var-lib-gitea.tar.$(RUN_EPOCH) attic/var-lib-gitea.tar + $(SSH) $(SSH_OPTS) root@`$(TF) output ipv4` 'tar --exclude /var/lib/gitea/unix-domain-socket -cvJf - /var/lib/gitea /etc/gitea' > attic/gitea.txz.$(RUN_EPOCH) + ln -f attic/gitea.txz.$(RUN_EPOCH) attic/gitea.txz .PHONY: backup-ssl backup-ssl: attic - $(SSH) $(SSH_OPTS) root@`$(TF) output ipv4` 'tar cvf - /etc/ssl/uacme' > attic/etc-ssl-uacme.tar.$(RUN_EPOCH) - ln -sf attic/etc-ssl-uacme.tar.$(RUN_EPOCH) attic/etc-ssl-uacme.tar + $(SSH) $(SSH_OPTS) root@`$(TF) output ipv4` 'tar cvJf - /etc/ssl/uacme' > attic/uacme.txz.$(RUN_EPOCH) + ln -f attic/uacme.txz.$(RUN_EPOCH) attic/uacme.txz + +.PHONY: backup-syncthing +backup-syncthing: attic + $(SSH) $(SSH_OPTS) root@`$(TF) output ipv4` 'tar cvJf - /var/lib/syncthing' > attic/syncthing.txz.$(RUN_EPOCH) + ln -f attic/syncthing.txz.$(RUN_EPOCH) attic/syncthing.txz diff --git a/functionalidiot.com.tf b/functionalidiot.com.tf index ff791f5..f9634a8 100644 --- a/functionalidiot.com.tf +++ b/functionalidiot.com.tf @@ -8,6 +8,16 @@ variable "cloudflare_functionalidiot_zoneid" { type = string } +variable "short_dns_ttl" { + type = bool + default = true + description = "Whether to set short dns ttl's or not." +} + +locals { + dns_ttl = var.short_dns_ttl ? 120 : 43200 +} + resource "cloudflare_record" "root" { depends_on = [ linode_instance.prod, @@ -17,7 +27,7 @@ resource "cloudflare_record" "root" { name = "@" value = linode_instance.prod.ip_address type = "A" - ttl = 120 + ttl = local.dns_ttl } resource "cloudflare_record" "splat" { @@ -29,7 +39,7 @@ resource "cloudflare_record" "splat" { name = "*" value = linode_instance.prod.ip_address type = "A" - ttl = 1 + ttl = local.dns_ttl } # resource "cloudflare_record" "root6" { @@ -41,7 +51,7 @@ resource "cloudflare_record" "splat" { # name = "@" # value = local.ipv6 # type = "AAAA" -# ttl = 120 +# ttl = local.dns_ttl # } # resource "cloudflare_record" "splat6" { @@ -53,7 +63,7 @@ resource "cloudflare_record" "splat" { # name = "*" # value = local.ipv6 # type = "AAAA" -# ttl = 1 +# ttl = local.dns_ttl # proxied = true # } @@ -65,7 +75,7 @@ resource "cloudflare_record" "www" { name = "www" value = "functionalidiot.com" type = "CNAME" - ttl = 120 + ttl = local.dns_ttl } resource "cloudflare_record" "git" { @@ -76,7 +86,111 @@ resource "cloudflare_record" "git" { name = "git" value = "functionalidiot.com" type = "CNAME" - ttl = 120 + ttl = local.dns_ttl +} + +# MX record setup for fastmail dkim/spf on root and all subdomains +resource "cloudflare_record" "mx-cname-1" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "fm1._domainkey" + value = "fm1.functionalidiot.com.dkim.fmhosted.com" + type = "CNAME" + ttl = local.dns_ttl +} + +resource "cloudflare_record" "mx-cname-2" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "fm2._domainkey" + value = "fm2.functionalidiot.com.dkim.fmhosted.com" + type = "CNAME" + ttl = local.dns_ttl +} + +resource "cloudflare_record" "mx-cname-3" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "fm3._domainkey" + value = "fm3.functionalidiot.com.dkim.fmhosted.com" + type = "CNAME" + ttl = local.dns_ttl +} + +resource "cloudflare_record" "mx-10-root" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "@" + value = "in1-smtp.messagingengine.com" + type = "MX" + priority = "10" + ttl = local.dns_ttl +} + +resource "cloudflare_record" "mx-20-root" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "@" + value = "in2-smtp.messagingengine.com" + type = "MX" + priority = "20" + ttl = local.dns_ttl +} + +resource "cloudflare_record" "mx-10-splat" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "*" + value = "in1-smtp.messagingengine.com" + type = "MX" + priority = "10" + ttl = local.dns_ttl +} + +resource "cloudflare_record" "mx-20-splat" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "*" + value = "in2-smtp.messagingengine.com" + type = "MX" + priority = "20" + ttl = local.dns_ttl +} + +resource "cloudflare_record" "txt-mx-root" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "@" + value = "v=spf1 include:spf.messagingengine.com ?all" + type = "TXT" + ttl = local.dns_ttl +} + +resource "cloudflare_record" "txt-mx-splat" { + depends_on = [ + cloudflare_record.root, + cloudflare_record.splat ] + zone_id = var.cloudflare_functionalidiot_zoneid + name = "*" + value = "v=spf1 include:spf.messagingengine.com ?all" + type = "TXT" + ttl = local.dns_ttl } resource "cloudflare_record" "functionalidiot_com_ns1" { @@ -94,8 +208,8 @@ resource "cloudflare_record" "functionalidiot_com_ns2" { } resource "null_resource" "functionalidiot_com_setup_new_gitea" { - depends_on = [ null_resource.post_setup ] - count = fileexists("${path.module}/attic/var-lib-gitea.tar") ? 0 : 1 + depends_on = [ null_resource.gitea_install ] + count = fileexists("${path.module}/attic/gitea.txz") ? 0 : 1 connection { host = linode_instance.prod.ip_address user = "root" @@ -126,62 +240,71 @@ chown gitea:www-data /var/lib/gitea/db/gitea.db su - gitea -c "gitea migrate --config /etc/gitea/app.ini" -su - gitea -c "gitea admin create-user --username mitch --password ${var.gitea_db_passwd} --email spam@mitchty.com --admin --config /etc/gitea/app.ini" +su - gitea -c "gitea admin create-user --username mitchty --password ${var.gitea_db_passwd} --email git@functionalidiot.com --admin --config /etc/gitea/app.ini" FIN ] } } -resource "null_resource" "functionalidiot_com_setup_saved_uacme" { - depends_on = [ null_resource.post_setup ] - count = fileexists("${path.module}/attic/etc-ssl-uacme.tar") ? 1 : 0 +resource "null_resource" "functionalidiot_com_setup_saved_gitea" { + depends_on = [ null_resource.gitea_install ] + count = fileexists("${path.module}/attic/gitea.txz") ? 1 : 0 connection { host = linode_instance.prod.ip_address user = "root" private_key = file("~/.ssh/id_rsa") } provisioner "file" { - source = "etc-ssl-uacme.tar" - destination = "/tmp/etc-ssl-uacme.tar" + source = "${path.module}/attic/gitea.txz" + destination = "/tmp/gitea.txz" } # TODO: Finish post untar setup provisioner "remote-exec" { inline = [<