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.52k stars 9.52k forks source link

v0.12-alpha1 terraform get error parsing HCL2 syntax #20024

Closed SpencerBrown closed 5 years ago

SpencerBrown commented 5 years ago

Terraform Version

Terraform v0.12.0-alpha1

Terraform Configuration Files

variable "bar" {
  default = "foobar"
}

resource "local_file" "foo" {
  filename = "foo.bar"
  content = var.bar
}

Debug Output


Spencer-Brown:bug spencer$ TF_LOG=trace terraform get
2019/01/16 07:54:43 [INFO] Terraform version: 0.12.0 alpha1
2019/01/16 07:54:43 [INFO] Go runtime version: go1.11.4
2019/01/16 07:54:43 [INFO] CLI args: []string{"/Users/spencer/bin/terraform", "get"}
2019/01/16 07:54:43 [DEBUG] Attempting to open CLI config file: /Users/spencer/.terraformrc
2019/01/16 07:54:43 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019/01/16 07:54:43 [INFO] CLI command args: []string{"get"}
Error loading configuration: Error parsing /Users/spencer/mongodb/tf-x509/bug/main.tf: At 7:13: Unknown token: 7:13 IDENT var.bar

Crash Output

Expected Behavior

terraform get should not error because I have an HCL2 variable value without the "${}"

Actual Behavior

Error loading configuration: Error parsing /Users/spencer/mongodb/tf-x509/bug/main.tf: At 7:13: Unknown token: 7:13 IDENT var.bar

Steps to Reproduce

  1. terraform init
  2. terraform validate
  3. terraform get

Additional Context

saw this error with alpha1, also tried with master branch of terraform, same error

References

jbardin commented 5 years ago

Hi @SpencerBrown

Sorry for the inconvenience here. That release is a few moths out of date; the latest alpha is v0.12.0-alpha4. The bare variable syntax should work with the latest alpha and with the current master as well.

SpencerBrown commented 5 years ago

@jbardin thanks for the response. As i mentioned I also see this error in master, unless I'm doing something wrong in the build. Even simpler repro:

variable "bar" {
  default = "foobar"
}

output "foo" {
  value = var.bar
}


Spencer-Brown:bug spencer$ terraform -v
Terraform v0.12.0-dev
Spencer-Brown:bug spencer$ terraform apply

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

foo = foobar
Spencer-Brown:bug spencer$ terraform get
Error loading configuration: Error parsing /Users/spencer/mongodb/tf-x509/bug/main.tf: At 11:11: Unknown token: 11:11 IDENT var.bar
Spencer-Brown:bug spencer$
apparentlymart commented 5 years ago

Hi @SpencerBrown!

It does seem like something weird is going on here, since that error message looks like what we'd expect to see from the old config parser (0.11 and earlier) rather than new. Perhaps there's some remnant code still calling into the old parser somewhere.

I'm going to re-open this so we can investigate further and see what's going on before we do v0.12.0 final.

jbardin commented 5 years ago

Sorry, that was my error parsing, terraform get is the issue here. Looks like get is still calling the old config loader to list module sources.

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.