Comments (3)
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.
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.
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)
- Scanning error for quoted templates ending with $ or % HOT 1
- heredocs aren't properly closed during indent fomartting HOT 1
- Merge into hashicorp/hcl HOT 3
- Avoid Duplicate HOT 1
- Argument or block definition required terraform HOT 1
- Clarify whether tabs are accepted or not HOT 2
- Unable to parse terraform variables HOT 4
- Continuous Fuzzing
- Formatter inserts unwanted space between two consecutive interpolation sequences
- Splat on a null should return an empty sequence
- hclpack: Attributes being mixed up in content()
- gohcl.EncodeIntoBody ignores optional elements HOT 1
- Template parsing allowing mixed escapes HOT 1
- Format doesn't correct handle block content after newline HOT 2
- Confusing error in HCL1-style map HOT 2
- Forbid zero-prefixed number literals to avoid octal confusion HOT 1
- Missing newline after comment at EOF causes error HOT 2
- Question: how to decode a custom type and validate it? HOT 2
- Inaccurate diagnostics context for nested fields HOT 2
- feat: struct field tag should support both block and optional HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hcl2.