Giter Club home page Giter Club logo

Comments (3)

apparentlymart avatar apparentlymart commented on August 22, 2024

Hi @bernadinm,

I think actually the problem there is that period is not a valid character in an identifier, and unquoted map keys are now required to be identifiers. Wrapping those strings in quotes should get the desired effect. However, that error message could certainly be more actionable by noticing that the next character is a period and stating more specifically that periods are not allowed there and to put the value in quotes, since indeed HCL1 was more forgiving about that.

from hcl2.

apparentlymart avatar apparentlymart commented on August 22, 2024

Having looked more closely at this, I see that it's a more subtle problem than I first thought.

The string centos_7.2_ap-south-1 tokenizes as Ident("centos_7") Dot Number(2) Ident("_ap-south-1"), because an identifier can't start with a digit. This means the parser interprets it as an alternative syntax for centos_7[2] and then terminates expression parsing, returning to the object constructor parser with Ident("_ap-south-1") as the next token, which then fails because an = is expected there.

This means we can't get quite as precise a helpful error message as I originally hoped, but I'm going to add a "Did you mean...?" suggestion to the error message in the situation where an identifier appears right after the attribute key expression to at least give a hint as to what fix is required here.

Some good news side from that is that for Terraform 0.12 in particular it will include a tool to help with making these upgrades and it will be able to make this particular fix automatically, wrapping your keys here in quotes once it detects that they are not valid HCL2 identifiers.

from hcl2.

apparentlymart avatar apparentlymart commented on August 22, 2024

In 7ace05a I have added two new error messages, one of which addresses the situation you encountered here. As noted in my previous comment, we can't recognize this pattern unambiguously and so I instead phrased the error message as a hint as to what the problem might be:

Error: Missing key/value separator

  (source code reference)

Expected an equals sign ("=") to mark the beginning of the attribute
value. If you intended to given an attribute name containing periods
or spaces, write the name in quotes to create a string literal.

This combined with the Terraform-specific configuration upgrade tool is, I think, the best we can do here without introducing confusing ambiguities into the language now that object/map keys are allowed to be arbitrary expressions rather than just literal strings. This is one of the situations where a slight incompatibility is an unavoidable consequence of supporting first-class expressions where HCL 1 did not.

from hcl2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.