3 ms·
orly, what structure does this represent? outer { example { foo = "bar" } example { foo = "baz" } } it reminds me of the insan
by mdaniel 1y ago
orly, what structure does this represent?
outer {
example {
foo = "bar"
}
example {
foo = "baz"
}
}
it reminds me of the insanity of toml
[lol]
[[whut]]
foo = "bar"
[[whut]]
foo = "baz"
only at least with toml I can $(python3.13 -c 'import tomllib, sys; print(tomllib.loads(sys.stdin.read()))') to find out, but with hcl too bad
- XorNot 1y agoOh thank god I'm not the only one who sees it. People complain about YAML then go and use TOML.
- eddythompson80 1y agoThe block config syntax isn't that confusing. Nginx had it for years. this is the same as server { location / { return 200 "OK"; } location /error { return 404 "Error"; } } server { location / { return 200 "OK"; } location /error { return 404 "Error"; } } But because we know that nginx is a configuration language for a server where we define the behavior we want through creating a set of resources (servers in this example, but "example"s or "whut"s in yours) { "servers": [ { "locations": [ { "key": "/", "return": { "status": 200, "content": "OK" } }, { "key": "/error", "return": { "status": 404, "content": "error" } } ] }, { "locations": [ { "key": "/", "return": { "status": 200, "content": "OK" } }, { "key": "/error", "return": { "status": 404, "content": "error" } } ] } ] }
- mdaniel 1y agoI am glad that you don't find the syntax confusing, but in my 25 years of monkeying with computer stuff, [] have been the canonical "I have a list of things" characters for a long as I can remember, so I sure am glad that Hashicorp decided that just repeating the key name is how one indicates list membership I did see the "inspired by nginx" on hcl's readme, but that must be why you and Mitchell like hcl so much because I loathe nginx's config with all my heart
- eddythompson80 1y agoI was just saying HCL didn't invent block config. Perhaps nginx, Caddy, Lisp, F#'s Computation Expressions all primed me for HCL style syntax so it looks pretty clear to me. The key is understanding the value of that "repeating the key name", because it doesn't just become a keyname, it becomes a constructor and makes the syntax much simpler. At the end of the day HCL isn't that much more complex than something like yaml. Saying "You don't want your developers learning yaml" is like saying "You don't want your developers learning Yaml. They send an email to the SRE guys, and the SRE guys are the Yaml experts"
- dangus 1y agoThat isn’t even valid HCL.
- mdaniel 1y agoUh-huh, I think you are secretly supporting my argument of "who can possibly decipher this insanity?!" because https://github.com/tmccombs/hcl2json https://github.com/tmccombs/hcl2json believes that it is valid $ hcl2json <<FOO | jq -r '"has \(length) keys"' outer { example { foo = "bar" } example { foo = "baz" } } FOO has 1 keys
- dangus 1y agoWhy do I care what some random guy’s HCL to JSON conversion tool thinks is valid? Terraform converts HCL to JSON in a different way that makes a lot more sense, and hcldec provided by Hashicorp lets you define your own specification for how you want to use it. I would like to point out that perfect compatibility with JSON is not a goal nor a requirement of a decent configuration language.
- mdaniel 1y agoYou seem to have skipped over your initial citation of it being invalid syntax, to say nothing of the sibling comment to yours also using that opaque syntax As for why I linked to "some random guy," that's because the Hashicorp people in their infinite wisdom didn't ship any rendering binary so some kind soul had to glue one to the official sdk https://github.com/tmccombs/hcl2json/blob/v0.6.7/go.mod#L8 https://github.com/tmccombs/hcl2json/blob/v0.6.7/go.mod#L8 I hear you about JSON might not be a goal, but I can tell you that Terraform accepts .json files just as much as it accepts .hcl files so that sane people can generate them, because sane people cannot generate HCL https://developer.hashicorp.com/terraform/language/syntax/json#json-configuration-syntax https://developer.hashicorp.com/terraform/language/syntax/js...
- jitl 1y agoHashicorp ships official packages that wrap hcl2json: https://www.npmjs.com/package/@cdktf/hcl2json https://www.npmjs.com/package/@cdktf/hcl2json https://github.com/hashicorp/terraform-cdk/tree/main/packages/%40cdktf/hcl2json https://github.com/hashicorp/terraform-cdk/tree/main/package... I use the package to implement module dependency graph tracking across our terraform monorepo for things like code reviews and CI triggering.