Terraform and MX DNS Record - DNS Validation Error 1004

Man, my issue is pretty simple and I’m lost, I’m creating my zone and some dns records with Terraform and they’re all working just fine, zone, records and settings, EXCEPT, twoMX records that I can’t for the love of the gods, understand why.

I’m using the following code

resource "cloudflare_record" "zone_dns_records_mx1" {
  zone_id 	= "<my zone id>"
  type    	        = "MX"
  name       	= "@"
  value   	        = "<the domain I'm using>"
  proxied 	        = false
}

And terraform is generating this plan

+ resource "cloudflare_record" "zone_dns_records_mx1" {
      + allow_overwrite = false
      + created_on      = (known after apply)
      + hostname        = (known after apply)
      + id              = (known after apply)
      + metadata        = (known after apply)
      + modified_on     = (known after apply)
      + name            = "@"
      + proxiable       = (known after apply)
      + proxied         = false
      + ttl             = (known after apply)
      + type            = "MX"
      + value           = "<the domain I'm using>"
      + zone_id         = "<my zone id>"
    }

And the error;

Error: failed to create DNS record: DNS Validation Error 1004

  with cloudflare_record zone_dns_records_mx1,
  on main.tf line 25, in resource "cloudflare_record" "zone_dns_records_mx1":
  25: resource "cloudflare_record" "zone_dns_records_mx1" {

It looks like you’re missing the priority value for the MX record.
It should look something like this

resource "cloudflare_record" "zone_dns_records_mx1" {
  zone_id   = "<zone id>"
  type      = "MX"
  name      = "@"
  value     = "<domain I'm using>"
  priority  = <priority>
  proxied   = false
}
3 Likes

BRO.

WHY?

W

H

Y

?

lol

I’m using a yaml file to setup the blueprint so I can reuse in other stuff and whatnot, it doesn’t really matter, so my yaml looks like this;

- id: mx2
  type: "MX"
  name: "@"
  value: "<domain>"
  priority: 20

It has the priority.

My actual code doesn’t, for pete sake.

resource “cloudflare_record” “zone_dns_records” {
for_each = { for i, record in var.shared.dns_records : record.id => record }
zone_id = cloudflare_zone.zone.id
type = each.value.type
name = each.value.name == “@” ? var.zone.name : each.value.name
value = each.value.value == “@” ? var.zone.name : each.value.value
proxied = try(each.value.proxied, null)
}

I was reading “proxied” as “priority” and… ■■■■. I feel so stupid. hahaha :')

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.