resource "digitalocean_domain" "enpaul" {
  name = "enpaul.net"
}


# ==========================================================================
# Standard hostname configuration
resource "digitalocean_record" "enpaul" {
  domain = digitalocean_domain.enpaul.id
  type   = "A"
  name   = "@"
  value  = "24.2.156.189"
  ttl    = 3600
}

resource "digitalocean_record" "enpaul_www" {
  domain = digitalocean_domain.enpaul.id
  type   = "CNAME"
  name   = "www"
  value  = "@"
  ttl    = 10800
}


# ==========================================================================
# Standard DO configuration for all managed domains, includes
# NS records and SOA
resource "digitalocean_record" "enpaul_ns1" {
  domain = digitalocean_domain.enpaul.id
  type   = "NS"
  name   = "@"
  value  = "ns1.digitalocean.com."
  ttl    = 1800
}

resource "digitalocean_record" "enpaul_ns2" {
  domain = digitalocean_domain.enpaul.id
  type   = "NS"
  name   = "@"
  value  = "ns2.digitalocean.com."
  ttl    = 1800
}

resource "digitalocean_record" "enpaul_ns3" {
  domain = digitalocean_domain.enpaul.id
  type   = "NS"
  name   = "@"
  value  = "ns3.digitalocean.com."
  ttl    = 1800
}


# ==========================================================================
# DMARC and HTTPS security configuration
resource "digitalocean_record" "enpaul_dmarc" {
  domain = digitalocean_domain.enpaul.id
  type   = "TXT"
  name   = "_dmarc"
  value  = "v=DMARC1; p=quarantine; adkim=s"
  ttl    = 3600
}

resource "digitalocean_record" "enpaul_caa" {
  domain = digitalocean_domain.enpaul.id
  type   = "CAA"
  name   = "@"
  value  = "letsencrypt.org."
  ttl    = 3600
  tag    = "issue"
  flags  = 0
}


# ==========================================================================
# Tutanota mailer integration configuration
resource "digitalocean_record" "enpaul_mx" {
  domain   = digitalocean_domain.enpaul.id
  type     = "MX"
  name     = "@"
  value    = "mail.tutanota.de."
  ttl      = 3600
  priority = 10
}

resource "digitalocean_record" "enpaul_spf" {
  domain   = digitalocean_domain.enpaul.id
  type     = "TXT"
  name     = "@"
  value    = "v=spf1 include:spf.tutanota.de -all"
  ttl      = 3600
}

resource "digitalocean_record" "enpaul_domainkey1" {
  domain   = digitalocean_domain.enpaul.id
  type     = "CNAME"
  name     = "s1._domainkey"
  value    = "s1._domainkey.tutanota.de."
  ttl      = 10600
}

resource "digitalocean_record" "enpaul_domainkey2" {
  domain   = digitalocean_domain.enpaul.id
  type     = "CNAME"
  name     = "s2._domainkey"
  value    = "s2._domainkey.tutanota.de."
  ttl      = 10600
}

resource "digitalocean_record" "enpaul_mta1" {
  domain   = digitalocean_domain.enpaul.id
  type     = "CNAME"
  name     = "_mta-sts"
  value    = "_mta-sts.tutanota.com."
  ttl      = 10600
}

resource "digitalocean_record" "enpaul_mta2" {
  domain   = digitalocean_domain.enpaul.id
  type     = "CNAME"
  name     = "mta-sts"
  value    = "mta-sts.tutanota.com."
  ttl      = 10600
}
