0

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.

  • I thought I had it fixed, but turns out, not so much. When I manually create it with a name of "@" it works, but if I terraform it with that name I get a subdomain with the name of "@.example.com". – PlexQ Dec 17 '19 at 18:50
  • looks like from the terraform docs.. you don't need to add the period at the end of the FQDN for the exhange's – Mike Dec 23 '19 at 20:36
  • @Mike turns out if you do that’s you get the expected result, mx.example.com.example.com, – PlexQ Dec 24 '19 at 23:09
0

Turn out it’s a missing feature in the azure plugin, they have made a patch and looks like it’ll be in 1.40.0

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.