# Input variables variable "vultr_api_key" { type = string description = "Vultr API key." } variable "tld" { type = string description = "Root Top-Level Domain. Subdomains will be derived from it." } variable "hostname" { type = string description = "Human name of the host. This is a pet name, not cattle name :)" } variable "dkim_public_key" { type = string description = "Public key for the DNS TXT DKIM record." } variable "dkim_selector" { type = string description = "The DKIM selector that prefixes the domain in the TXT record." } # Vultr provider "vultr" { api_key = var.vultr_api_key } # Instance resource "vultr_server" "vps_server" { enable_ipv6 = true notify_activate = true auto_backup = true hostname = var.hostname label = var.hostname # $ curl https://api.vultr.com/v1/regions/list | jq '.["9"]' region_id = 9 # $ curl https://api.vultr.com/v1/plans/list?type=vc2 | jq '.["201"]' plan_id = 201 # $ curl -H "API-Key: $TF_VAR_vultr_api_key" https://api.vultr.com/v1/snapshot/list | jq snapshot_id = "5c35fb3a74873" # base-guix-image } output "public_ipv4" { value = vultr_server.vps_server.main_ip } output "public_ipv6" { value = vultr_server.vps_server.v6_networks[0].v6_main_ip } # DNS and IP configuration locals { mail_domain = "mail.${var.tld}" } resource "vultr_dns_domain" "vps_tld" { # The CNAME record is already generated by Vultr domain = var.tld server_ip = vultr_server.vps_server.main_ip } resource "vultr_dns_record" "vps_mail_a_record" { domain = var.tld name = "mail" data = vultr_server.vps_server.main_ip type = "A" } resource "vultr_reverse_ipv4" "vps_mail_reverse_ipv4" { instance_id = vultr_server.vps_server.id ip = vultr_server.vps_server.main_ip reverse = local.mail_domain } resource "vultr_dns_record" "vps_mail_aaaa_record" { domain = var.tld name = "mail" data = vultr_server.vps_server.v6_networks[0].v6_main_ip type = "AAAA" } resource "vultr_reverse_ipv6" "vps_mail_reverse_ipv6" { instance_id = vultr_server.vps_server.id ip = vultr_server.vps_server.v6_networks[0].v6_main_ip reverse = local.mail_domain } resource "vultr_dns_record" "vps_mx_record" { domain = var.tld name = "" data = local.mail_domain type = "MX" } resource "vultr_dns_record" "vps_spf_txt" { domain = var.tld name = "" data = "\"v=spf1 mx -all\"" type = "TXT" } resource "vultr_dns_record" "vps_dkim_txt" { domain = var.tld name = "${var.dkim_selector}._domainkey" data = "\"v=DKIM1;k=rsa;p=${var.dkim_public_key}\"" type = "TXT" } resource "vultr_dns_record" "vps_dmarc_txt" { domain = var.tld name = "_dmarc" data = "\"v=DMARC1;p=none;pct=100;rua=mailto:postmaster@${var.tld};\"" type = "TXT" } resource "vultr_dns_record" "vps_cname_start_alias" { domain = var.tld name = "*" data = var.tld type = "CNAME" }