-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arrays where they shouldn't be #3
Comments
Thanks for reporting! We're mostly using the other way around ourselves. We switched to the official hcl repo in #2, and I think this behavior should be reported upstream there, since we're merely a simple wrapper around its printer functions (also see https://github.com/kvz/json2hcl/blob/master/main.go#L40) so I don't think this is something we can/should patch at our level. Sorry I can't be of more help! |
Personally, I do not believe that this is a bug or misbehavior of the official hcl package. I spent some time building a function to remove the unnecessary arrays but you will eventually hit some unfortunate situations when creating arrays by repeating the same block, e.g.: "basic-dynamodb-table" = {
"attribute" = {
"name" = "TopScore"
"type" = "N"
}
"attribute" = {
"name" = "UserId"
"type" = "N"
}
} Right now, this will interpreted as "basic-dynamodb-table": [
{
"attribute": [
{
"name": "TopScore",
"type": "N"
},
{
"name": "UserId",
"type": "N"
}
]
However, if we start to remove those arrays, it turns into this: "basic-dynamodb-table": {
"attribute": {
"name": [
"TopScore",
"UserId"
],
"type": [
"N",
"N"
]
}, Notice, that |
Hmm... thanks for the info, @Acconut. I'm going to open an issue upstream nonetheless, and see if they can shed some light (even if it just becomes a tally mark for clarifying the config format used by various tools). |
Thank you for bringing this issue up in Hashicorp's repository. I will monitor the discussion and see how we can improve the tool. |
I'm running into a similar issue, but with Terraform. Under the root node, there is a variables key with a value that the tool is turning into an array, when it should be a hash/dictionary. Is this the same core issue? |
@erick-thompson Most likely, yes, but it would be nice if you could supply an example for us to check it. |
Sure. I'll paste a shortened example here. If you need the full files, I can upload them. The HCL is
When I run the tool with reverse, I get
The problem here is that "variable" is set to an array, but terraform expects it to be a hash/dictionary (this is true for all other resource types as well). So if I then convert the json (module omitted for clarity) to:
Then terraform works fine. The problem is that, except for list variables, I don't believe that terraform ever wants arrays, but the output of this tool has arrays everywhere. BTW, thanks for putting this tool together. HCL is great for humans to work with, but it isn't great to automate. Thanks, |
@erick-thompson Unfortunately, this is the same problem as above and therefore we cannot do much about this. :| |
That is what I figured. Any point in filing an issue in the terraform repo? |
I don't think so. This is not a problem with Terraform but instead arises because HCL cannot be directly mapped to JSON (see hashicorp/hcl#162 (comment)). |
Thanks. I chimed in on the thread just in case. BTW thanks for the awesome project. It's allowed me to figure out what variables are in play. |
Thank you for your kind words :) |
This is the workaround I currently use, because I need the extra [] to be gone:
It's not nice but at least for me it gets the job done. |
Thanks, @gellweiler. Unfortunately, I do not think this code works for all use cases. |
My solution is not clean, but it's quite effective if your use-case is specific. For example, I'm stripping spurious arrays from a
There might be a way to do this in one line, but I feel that the above is more readable and manageable. I hope it helps anyone who might get stuck here. |
I'm using
-reverse
to convert an HCL file, specifically configuration for the HashiCorp Vault Secure Introduction client (a proprietary, Enterprise-only Vault add-on); HCL example here to JSON.The input is:
However, using the current 0.0.6 version, the JSON output is:
This is detected as invalid by VSI, even though the HCL file works correctly. It appears that the problem is that there are extra arrays inserted. The working JSON from this HCL seems to be:
The text was updated successfully, but these errors were encountered: