hcl2json
hcl2json copied to clipboard
Convert from JSON to HCL2
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"
}
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?
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.