tf-infra/mailserver.tf
Lander Van den Bulcke 3277efc713
feat: add mailserver
Signed-off-by: Lander Van den Bulcke <landervandenbulcke@gmail.com>
2025-07-01 23:51:35 +02:00

75 lines
1.9 KiB
HCL

resource "hcloud_floating_ip" "mail" {
type = "ipv4"
home_location = "fsn1"
}
resource "hcloud_rdns" "floating_mail" {
floating_ip_id = hcloud_floating_ip.mail.id
ip_address = hcloud_floating_ip.mail.ip_address
dns_ptr = "mail.escapeangle.com"
}
data "cloudflare_zone" "escapeangle" {
filter = {
name = "escapeangle.com"
}
}
resource "cloudflare_dns_record" "mail-a" {
zone_id = data.cloudflare_zone.escapeangle.id
name = "mail.escapeangle.com"
content = hcloud_floating_ip.mail.ip_address
type = "A"
ttl = "10800"
}
resource "cloudflare_dns_record" "mail-mx" {
zone_id = data.cloudflare_zone.escapeangle.id
name = "escapeangle.com"
content = "mail.escapeangle.com"
type = "MX"
priority = 10
ttl = "10800"
}
resource "cloudflare_dns_record" "mail-spf" {
zone_id = data.cloudflare_zone.escapeangle.id
name = "escapeangle.com"
content = "v=spf1 a:mail.escapeangle.com -all"
type = "TXT"
ttl = "10800"
}
resource "cloudflare_dns_record" "mail-dkim" {
zone_id = data.cloudflare_zone.escapeangle.id
name = "mail._domainkey.escapeangle.com"
content = "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJEouqeGAu4u4+UJY6NfdiwIoRghb4nJksa3CEZKGgy5CHJrjZ68urRzeKJPkGau8bK/yW9vte4VJ4IlIStdmkwSNqwdnBB/klTW1WZijhpKgN7rTioitQz2B2gJzOt7m1fbt9+BCLiPCmz8V3HNm36DHr+N7a69py7K8YlzZnPQIDAQAB"
type = "TXT"
ttl = "10800"
}
resource "cloudflare_dns_record" "mail-dmarc" {
zone_id = data.cloudflare_zone.escapeangle.id
name = "_dmarc.escapeangle.com"
content = "v=DMARC1; p=none"
type = "TXT"
ttl = "10800"
}
module "mailserver" {
source = "./modules/server"
hostname = "mail-01"
dns_zone = "escapeangle.com"
location = "fsn1"
}
resource "hcloud_floating_ip_assignment" "mail" {
floating_ip_id = hcloud_floating_ip.mail.id
server_id = module.mailserver.server_id
}