Skip to content

cloudflare_dns_record priority input not working unless nested under data #6651

@rashedobaid

Description

@rashedobaid

Confirmation

  • This is a bug with an existing resource and is not a feature request or enhancement. Feature requests should be submitted with Cloudflare Support or your account team.
  • I have searched the issue tracker and my issue isn't already found.
  • I have replicated my issue using the latest version of the provider and it is still present.

Terraform and Cloudflare provider version

Opentofu:

OpenTofu v1.11.2
on darwin_arm64

terraform.lock:

provider "registry.opentofu.org/cloudflare/cloudflare" {
  version     = "5.15.0"
  constraints = ">= 5.5.0"
  hashes = [
    "h1:EY8mWQO1NTqXuxnZxwVppF7AiLRdx7vRLYk6O7yzgPs=",
    "zh:20a72bdbb28435f11d165b367732369e8f8163100a214e89ad720dae03fafa0c",
    "zh:2eabd7a51fd7aafcab9861631d85c895914857e4fcd6fe2dd80bac22e74a1f47",
    "zh:62828afbc1ba0e0a64bbb7d5d42ae3c2fbbaabb793010b07eba770ba91bae94f",
    "zh:6693f1021e52c34a629300fbcd91f8bd4ca386fda3b45aec746b9c200c28a42c",
    "zh:6873a15454b289e5baecc1d36ce8997266438761386a320753c63f13407f4a6b",
    "zh:afbf4e56b3a5e5950b35b02b553313e4a2008415920b23f536682269c64ca549",
    "zh:db367612900bc2e5a01c6a325e4cff9b1b04960ce9de3dd41671dda5a627ca1d",
    "zh:eb7365eafc6160c3b304a9ce6a598e5400a2e779e9e2bd27976df244f79f774f",
    "zh:f809ab383cca0a5f83072981c64208cbd7fa67e986a86ee02dd2c82333221e32",
  ]
}

provider "registry.opentofu.org/hashicorp/cloudflare" {
  version = "5.15.0"
  hashes = [
    "h1:EY8mWQO1NTqXuxnZxwVppF7AiLRdx7vRLYk6O7yzgPs=",
    "zh:20a72bdbb28435f11d165b367732369e8f8163100a214e89ad720dae03fafa0c",
    "zh:2eabd7a51fd7aafcab9861631d85c895914857e4fcd6fe2dd80bac22e74a1f47",
    "zh:62828afbc1ba0e0a64bbb7d5d42ae3c2fbbaabb793010b07eba770ba91bae94f",
    "zh:6693f1021e52c34a629300fbcd91f8bd4ca386fda3b45aec746b9c200c28a42c",
    "zh:6873a15454b289e5baecc1d36ce8997266438761386a320753c63f13407f4a6b",
    "zh:afbf4e56b3a5e5950b35b02b553313e4a2008415920b23f536682269c64ca549",
    "zh:db367612900bc2e5a01c6a325e4cff9b1b04960ce9de3dd41671dda5a627ca1d",
    "zh:eb7365eafc6160c3b304a9ce6a598e5400a2e779e9e2bd27976df244f79f774f",
    "zh:f809ab383cca0a5f83072981c64208cbd7fa67e986a86ee02dd2c82333221e32",
  ]
}

Affected resource(s)

cloudflare_dns_record

Terraform configuration files

resource "cloudflare_dns_record" "minecraft_srv" {
  zone_id = module.zone.id
  name    = "_minecraft._tcp.mc.${var.zone}"
  type    = "SRV"
  ttl     = 300
  priority = 1
  data = {
    weight   = 0
    port     = 25565
    target   = "mc.${var.zone}"
  }
}

Link to debug output

N/A

Panic output

No response

Expected output

Successful apply

Actual output


  ╷
  │ Error: failed to make http request
  │ 
  │   with cloudflare_dns_record.minecraft_srv[0],
  │   on minecraft.tf line 22, in resource "cloudflare_dns_record" "minecraft_srv":
  │   22: resource "cloudflare_dns_record" "minecraft_srv" {
  │ 
  │ PUT
  │ "https://api.cloudflare.com/client/v4/zones/80fbd65dc2421f9d26911465c3560a65/dns_records/e611d6b8be2f09141d893cc9d95a1667":
  │ 400 Bad Request
  │ {"result":null,"success":false,"errors":[{"code":9104,"message":"priority
  │ must be an integer between 0 and 65535."}],"messages":[]}
  ╵

Steps to reproduce

  1. tofu apply

Additional factoids

According to the documentation:

[priority] (Number) Required for MX, SRV and URI records; unused by other record types. Records with lower priorities are preferred.

This is not true and only works when nested inside the data input.

resource "cloudflare_dns_record" "minecraft_srv" {
  zone_id = module.zone.id
  name    = "_minecraft._tcp.mc.${var.zone}"
  type    = "SRV"
  ttl     = 300
  data = {
    priority = 1
    weight   = 0
    port     = 25565
    target   = "mc.${var.zone}"
  }
}

References

https://registry.terraform.io/providers/cloudflare/cloudflare/5.15.0/docs/resources/dns_record#optional
https://github.com/cloudflare/terraform-provider-cloudflare/blob/main/docs/resources/dns_record.md?plain=1#L47

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions