hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.04k stars 9.47k forks source link

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

Closed Noah-Huppert closed 7 years ago

Noah-Huppert commented 7 years ago

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

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.