hcl2json icon indicating copy to clipboard operation
hcl2json copied to clipboard

Convert from JSON to HCL2

Open samuelvl opened this issue 5 years ago • 2 comments

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"
}

samuelvl avatar Jul 26 '19 16:07 samuelvl

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 avatar Oct 08 '19 07:10 tmccombs

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.

DarkMukke avatar Jul 05 '22 17:07 DarkMukke