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.35k stars 9.49k forks source link

Improve error message for references (variables) missing resources. #32181

Open docwhat opened 1 year ago

docwhat commented 1 year ago

Terraform Version

❯ terraform version            
Terraform v1.3.4
on darwin_arm64
+ provider registry.terraform.io/hashicorp/google v4.42.0
+ provider registry.terraform.io/hashicorp/google-beta v4.42.0
+ provider registry.terraform.io/hashicorp/null v3.2.0
+ provider registry.terraform.io/hashicorp/random v3.4.3
+ provider registry.terraform.io/hashicorp/time v0.9.0

Terraform Configuration Files

locals {
  org_id = "123456789"
}

module "frobnitz" {
  source = "modules/frobulator"

  name = "zork"
  organization_id = org_id # Note, this should be local.org_id, but I've made a typo.
}

Debug Output

N/A

Expected Behavior

The error message should clearly point me to the problem, ideally with examples and a guess to what the author meant.

Example message:

The reference org_id is not in a valid <resource>.<attribute> form. Did you mean locals.org_id?

Actual Behavior

A reference to a resource type must be followed by at least one attribute access, specifying the resource name.

❯ terraform plan           
╷
│ Error: Invalid reference
│ 
│   on main.tf line 10:
│   10:   organization_id  = org_id
│ 
│ A reference to a resource type must be followed by at least one attribute access, specifying the resource name.
╵

Steps to Reproduce

  1. terraform init
  2. terraform plan

Additional Context

N/A

References

N/A

crw commented 1 year ago

Thanks for this request!