hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
373 stars 66 forks source link

Attribute or block definition required --> do not see any attibute missing. #35

Closed bhushan-rane closed 6 years ago

bhushan-rane commented 6 years ago

While making Terraform Registry resync for update on module, it failed with error: Attribute or block definition required: An attribute or block definition is required here. To define an attribute, use the equals sign "=" to introduce the attribute value.

But it is not giving proper message which explains about what exactly the issue is.

Below is snippet of issue: image

I hope, am on correct repo for bug. If it is known issue, let me know resolution.

apparentlymart commented 6 years ago

Hi @bhushan-rane!

Terraform Registry is unfortunately not passing through the source location information from this error message, and so the "here" in the message is left without any context. That's a limitation of the module registry itself, so I'll pass that on to the Terraform Registry team to see if it can be improved.

I ran the configuration in this module v1.1.0 through a build of Terraform that has HCL2 integrated into it (from our dev branch) and was able to reproduce this message with the source location information included:

Error: Attribute or block required

This is a correct error message for the new version of HCL, because it now allows arbitrary expressions to be used as keys within maps but not as arguments within nested blocks. This is one of the edge-cases where the new version is slightly incompatible with the old, as a result of introducing this new feature of dynamic map keys. (To be exact, the parser now treats libvirt_domain.ExICPworker.id as an expression evaluating to the id itself, rather than as a map key name. It'd need to be given in quotes to get the previous interpretation.

However, the fact that you saw this message in the registry with a module intended for Terraform 0.11 seems odd. The Terraform registry should be accepting modules using the old syntax, and indeed I was able to process your module successfully using the same parsing code that the Terraform registry codebase uses, which used the old (current, in Terraform's terms) HCL implementation.

If you'd like a quick workaround here, putting the map keys that contain dots in quotes should bypass this message. However, there does seem to be a Terraform Registry bug here which we should discuss further. I'm going to open an issue for this in the Terraform repository (since it's not a HCL-related issue) and then we can dig into it some more with the Terraform Registry team.

Thanks for pointing this out!