How do you set up a Domain MX record on Azure with Terraform's azurerm provider?
When you set up an MX record, it is normal to make the name the FQDN "example.com." (at least with BIND). Terraform/Azure however does not permit this naming. And the example docs at https://www.terraform.io/docs/providers/azurerm/r/dns_mx_record.html suggest using the name "test". This is clearly stupid as it then creates a MX record for the subdomain test.example.com - which is NOT what you generally want at all.
For example:
resource "azurerm_dns_mx_record" "example-com-mx" {
name = "mx"
resource_group_name = data.azurerm_resource_group.prod-rg.name
zone_name = azurerm_dns_zone.example-com.name
ttl = 300
record {
exchange = "ALT1.ASPMX.L.GOOGLE.COM."
preference = "5"
}
record {
exchange = "ALT2.ASPMX.L.GOOGLE.COM."
preference = "5"
}
record {
exchange = "ALT3.ASPMX.L.GOOGLE.COM."
preference = "10"
}
record {
exchange = "ALT4.ASPMX.L.GOOGLE.COM."
preference = "10"
}
record {
exchange = "verificationcodehere.mx-verification.google.com."
preference = "15"
}
}
works great if what you need a mail exchanger for mx.example.com! But not if you want a domain mail exchanger.