digitalocean / terraform-provider-digitalocean

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

Terraform prints dependency error instead of actual error if reference misconfigured resource #16

Closed hashibot closed 5 years ago

hashibot commented 7 years ago

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


Terraform Version

$ terraform -v
Terraform v0.9.6

Affected Resource(s)

All? Found bug with:

I believe this is a Terraform core issue.

Terraform Configuration Files

resource "digitalocean_floating_ip" "auto_chess" {
    droplet_id = "${digitalocean_droplet.auto_chess.region}" # <-- Important: This field is intentionally wrong, should cause validation error
    region = "${digitalocean_droplet.auto_chess.region}"
}

resource "digitalocean_domain" "noahhuppert_com" {
    name = "noahhuppert.com"
    ip_address = "${digitalocean_droplet.auto_chess.ipv4_address}" # Not important to issue, defined in other file
}

resource "digitalocean_record" "auto_chess" {
    domain = "${digitalocean_domain.noahhuppert_com.name}"
    name = "auto_chess"
    type = "A"
    value = "${digitalocean_floating_ip.auto_chess.ip_address}"
}

Debug Output

Gist

Panic Output

None

Expected Behavior

Terraform should inform the user that the value they provided for digitalocean_floating_ip.auto_chess.droplet_id is incorrect like so:

* module.auto-chess.digitalocean_floating_ip.auto_chess: droplet_id: cannot parse '' as int: strconv.ParseInt: parsing "nyc3": invalid syntax

Actual Behavior

Terraform claims that digitalocean_floating_ip.auto_chess.ip_address is not found. This causes one to start debugging their code for a link/dependency error (Calling terraform graph, adding depends_on to everything, etc...). Instead of debugging their code for an incorrect digitalocean_floating_ip.auto_chess.droplet_id value.

Steps to Reproduce

  1. Create a resource that is misconfigured
    • In the example above this is the digitalocean_floating_ip.auto_chess
    • The droplet_id parameter is intentionally set to be a digitalocean_droplet's region when it is supposed to be an id.
  2. Create another resource that relies on a parameter of that resource
    • In the example above this is the digitialocean_record.auto_chess
    • It relies on digitalocean_floating_ip.auto_chess.ip_address
  3. terraform plan
  4. Receive a incorrect / not-really-showing-root-problem dependency error
  5. Comment out the resource which is using the misconfigured resource
    • In the example above this would mean commenting out the digitalocean_record
  6. Receive the correct validation error about your misconfigured resource

Important Factoids

Error messages and example code are in a module named auto-chess. Not included in the example code is a digitalocean_droplet named auto_chess, this is not important to the issue.

References

None

andrewsomething commented 5 years ago

With the release of Terraform 0.12 and some additional validations we've added on the DigitalOcean provider side, I think we can now close this one out. The error message here is much more useful:

Error: Incorrect attribute value type

  on terraform-testing.tf line 18, in resource "digitalocean_floating_ip" "auto_chess":
  18:     droplet_id = "${digitalocean_droplet.auto_chess.region}"

Inappropriate value for attribute "droplet_id": a number is required.