Skip to content
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

Can this be used as jo for HCL? #88

Open
nikolay opened this issue Sep 26, 2023 · 9 comments
Open

Can this be used as jo for HCL? #88

nikolay opened this issue Sep 26, 2023 · 9 comments

Comments

@nikolay
Copy link

nikolay commented Sep 26, 2023

https://manpages.org/jo

@minamijoyo
Copy link
Owner

Could you describe your use case and what feature you expect? I have not used jo before, so I'm unsure what you are trying.

@nikolay
Copy link
Author

nikolay commented Sep 27, 2023

The use case is creating valid HCL from shell scripts.

@antonbabenko
Copy link

We call hcledit to manage HCL files in shell scripts like this:

# Create content of temporary main.tf file
hcledit attribute append module.wrapper.source "\"${relative_source_path}${module_dir}\"" --newline -f "$tmp_file_tf" -u
hcledit attribute append module.wrapper.for_each var.items --newline -f "$tmp_file_tf" -u

https://github.com/antonbabenko/pre-commit-terraform/blob/66a1469a7c7954d8469d7a6f79f4ffb8c9ae09bf/hooks/terraform_wrapper_module_for_each.sh#L350-L352

I am unsure what else jo offers but hcledit does not.

@nikolay
Copy link
Author

nikolay commented Sep 28, 2023

@antonbabenko Doesn't really work:

$ echo 'locals {}' | hcledit attribute append module.wrapper.source test --newline
locals {}

@antonbabenko
Copy link

Works for me:

$ echo 'locals {}' | hcledit attribute append locals.test "\"test\"" --newline
locals {
  test = "test"
}

The syntax can be a bit tricky to get right (especially for deeply nested structures).

@nikolay
Copy link
Author

nikolay commented Sep 29, 2023

@antonbabenko But I want to add a new element in the root. We need the equivalent of jo and eventually jq so that HCL becomes a first-class citizen and eliminate the need for temporary files.

@antonbabenko
Copy link

Yes, there are some limitations around making root blocks. I usually make a file with a placeholder and then modify it.

@nikolay
Copy link
Author

nikolay commented Sep 30, 2023

Sorry, I know everything's possible, but the idea I brought up, jo is the tool's ergonomics. Sadly, there's no sane JSON to HCL converter that outputs Terraform-like HCL, not just a twisted version of the JSON. A valid JSON is a valid HCL, so those conversion tools are useless unless the tool converts JSON to readable and meaningful like what every one of us writes for Terraform.

@minamijoyo
Copy link
Owner

What I understand is that apparently you like the comfort of jo, but I don't know how you want to improve hcledit specifically. Unless you can analyze the ergonomics of jo and make more specific requests, I don't know what to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants