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

Convert from JSON to HCL2 #2

Open
samuelvl opened this issue Jul 26, 2019 · 2 comments
Open

Convert from JSON to HCL2 #2

samuelvl opened this issue Jul 26, 2019 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@samuelvl
Copy link

samuelvl commented Jul 26, 2019

Having a result.json file with the following content:

{
    "var1": "foo",
    "var2": "bar",
    "var3": {
        "key": "value"
    }
}

Is it possible to retrieve HCL2 content back?

var1 = "foo"
var2 = "bar"
var3 = {
  key = "value"
}
@tmccombs
Copy link
Owner

tmccombs commented Oct 8, 2019

This is more difficult, since without knowing the schema for the data, it isn't possible to definitively know how to convert to hcl (for example, should var3 be an attribute or a block?).

But maybe there are reasonable assumptions that could be made?

@tmccombs tmccombs added the help wanted Extra attention is needed label Jun 13, 2020
tmccombs pushed a commit that referenced this issue Jul 29, 2021
Bumps [github.com/zclconf/go-cty](https://github.com/zclconf/go-cty) from 1.8.1 to 1.9.0.
- [Release notes](https://github.com/zclconf/go-cty/releases)
- [Changelog](https://github.com/zclconf/go-cty/blob/main/CHANGELOG.md)
- [Commits](zclconf/go-cty@v1.8.1...v1.9.0)

---
updated-dependencies:
- dependency-name: github.com/zclconf/go-cty
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@DarkMukke
Copy link

Since this is not something you could extract from just data alone ( as json just describes object data, while hcl is a notation for configuration), it is probably better to build this programmatically, as something needs to understand the meaning of this data, i would suggest https://github.com/ahzhezhe/terraform-generator as an example but there are many others out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants