digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
496 stars 265 forks source link

digitialocean_record will not create an SRV record with a Port value of 0 #475

Closed garethsaxby closed 4 years ago

garethsaxby commented 4 years ago

Terraform Version

terraform -v
Terraform v0.12.29
+ provider.digitalocean v1.20.0

Affected Resource(s)

digitalocean_record

Terraform Configuration Files

resource "digitalocean_domain" "main" {
  name = "example.com"
}

resource "digitalocean_record" "srv" {
  domain   = digitalocean_domain.main.name
  type     = "SRV"
  name     = "_caldav._tcp"
  priority = 0
  weight   = 0
  port     = 0
  value    = "@"
  ttl      = 3600
}

Expected Behavior

The DNS SRV record should be created with the valid value of 0 for the port number, subject to the domain being created successfully.

Actual Behavior

The terraform configuration is hard stopped by the following error, and an apply does not happen:


Error: expected port to be in the range (1 - 65535), got 0

  on dns.tf line 5, in resource "digitalocean_record" "srv":
   5: resource "digitalocean_record" "srv" {

Steps to Reproduce

  1. Run a terraform plan against the example Terraform Configuration file.

Important Factoids

A port number of 0 is a valid in an SRV record as per RFC 2782, and using a 0 for the port number works both over the Digital Ocean API and web interface successfully.

For a Digital Ocean API example, first create a valid domain, then run the following with the domain field updated and your own token in place of my redacted token (I have formatted the output for better legibility):

$ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <REDACTED" -d '{"type":"SRV","name":"_caldav._tcp","data":"www.example.com.","priority":0,"port":0,"ttl":1800,"weight":0,"flags":null,"tag":null}' "https://api.digitalocean.com/v2/domains/gs-test-example.com/records"

{
  "domain_record": {
    "id": 109234109,
    "type": "SRV",
    "name": "_caldav._tcp",
    "data": "www.example.com",
    "priority": 0,
    "port": 0,
    "ttl": 1800,
    "weight": 0,
    "flags": null,
    "tag": null
  }
}

References

Digital Ocean API - https://developers.digitalocean.com/documentation/v2/#create-a-new-domain-record RFC 2782 - https://tools.ietf.org/html/rfc2782

andrewsomething commented 4 years ago

Thanks for flagging this. Once this fix lands in godo, we can get this fixed here as well: https://github.com/digitalocean/godo/pull/360