-
Notifications
You must be signed in to change notification settings - Fork 66
Is dynamic walk of a file.Body possible without schema? #7
Comments
Seems like this is possible by asserting the body of the parsed file to
Opened a PR that updates the docs: #8 |
Hi @fatih! Nice to see you over here. 😀 Sorry things are still rather ill-documented in here. It's all still evolving and so I've not yet managed to write down a good overview of how it all fits together. The design philosophy here is quite a bit different than the prior HCL, and specifically more tailored to configuration with a well-defined structure, rather than arbitrary data structures. As I think you've concluded, the main API in the Type-asserting to the Totally dynamic parsing was not a goal I had in mind when defining the primary API here. The API design assumes applications will behave more like Terraform, having a generally-rigid structure but allowing arbitrary attributes in some specific blocks. The schema-driven parsing is key to the better-defined handling of JSON in HCL2, but indeed it does make some use-cases that were possible with HCL harder to achieve. Sorry for the remaining references to "zcl" left in some spots. That's the name of my side-project that was forked and renamed to HCL2 to give a sense of continuity from HCL/HIL, and although all of the code is updated (I think!) there are still numerous leftover references in comments and docs which I'm cleaning up as I find them. Thanks for pointing out and fixing several of them! |
Hi,
I have HCL file with custom blocks and user functions. I would like to walk the file to collect all variable references in the form of
var.foo
. These references can start with any kind of prefix, such asfoo.bar
,resource.bar
,server.ip
, etc.. This is needed so I can create a DAG to compute the references firsthand and pass the references later with aevalContext
to each block (so decoding works and the expressions are called). It seems like the without knowing the structure of the file this is not possible? Here is an example which I'm trying to do (diags errors are neglect for the sake of simplicity):Is there a way to walk the tree without knowing the structure and using Go structs to define it? Or maybe helper function that would allow me to collect all references?
Thanks
The text was updated successfully, but these errors were encountered: