digitalocean / terraform-provider-digitalocean

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

priority is required when domain record type is MX or SRV #2

Closed hashibot closed 5 years ago

hashibot commented 7 years ago

This issue was originally opened by @tvaughan as hashicorp/terraform#2561. It was migrated here as part of the provider split. The original body of the issue is below.


Terraform's DigitialOcean domain_record documentation says that priority is optional. DigitalOcean's API documentation says that priority is required if the domain record type is MX or SRV. When priority is not provided in a terraform plan and it is required by the DigitalOcean API, this is the error:

* Failed to create record: Error creating record: API Error: unprocessable_entity: Priority is not a number and Priority Priority must be an integer between 0 and 65535

Tested on:

$ terraform --version
Terraform v0.5.3
$ lsb_release -a
No LSB modules are available.  
Distributor ID: Ubuntu
Description:    Ubuntu 15.04
Release:        15.04
Codename:       vivid
$ uname -m
x86_64

To reproduce:

resource "digitalocean_domain" "example" {
  ip_address = "127.0.0.1"
  name = "example.com"
}

resource "digitalocean_droplet" "mail" {
  image = "ubuntu-15-04-x64"
  name = "mail.${digitalocean_domain.example.name}"
  region = "nyc1"
  size = "512mb"
  ssh_keys = ["8675309"]
}

resource "digitalocean_record" "mail" {
  domain = "${digitalocean_domain.example.name}"
  name = "mail"
  type = "A"
  value = "${digitalocean_droplet.mail.ipv4_address}"
}

resource "digitalocean_record" "mx" {
  domain = "${digitalocean_domain.example.name}"
  type = "MX"
  value = "${digitalocean_record.mail.name}"
}

I'd like to submit a pull-request to resolve this. Should the DigitalOcean provider require priority, or provide a default value, like 10, when type is MX or SRV? FWIW - I assumed terraform would provide a default.

andrewsomething commented 5 years ago

We've added some additional validation here to make it clear that, like the API itself, priority is required if the domain record type is MX or SRV. We error out early to avoid the failed API request. Now on apply you would receive:

Error: `priority` is required for when type is `MX`

  on terraform-testing.tf line 29, in resource "digitalocean_record" "mx":
  29: resource "digitalocean_record" "mx" {