Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert HashiCorp Configuration Language into JSON?

Tags:

go

terraform

In order to better understand terraform I'd like to be able to translate HCL into the equivalent JSON. I got the HCL parser (https://github.com/hashicorp/hcl) to build and the tests to run but I don't see any command to take in an HCL file and output JSON.

There's a python implementation of HCL and it includes a utility that converts HCL to JSON, but it has some rather strange/unexpected behavior, and I would like to confirm that the behavior comes from the HCL language and isn't specific to the python implementation. e.g.

> cat foo.tf 
service {
    key = "aaa"
}

service {
    key = 0x10
    foo = "bar"
}

> hcltool foo.tf 
{
    "service": [
        {
            "foo": "bar",
            "key": "aaa"
        },
        {
            "key": 16
        }
    ]
}
like image 721
Darin Avatar asked Aug 04 '17 04:08

Darin


1 Answers

This site is useful for one-off conversions between HCL, JSON, and YAML: https://www.hcl2json.com/

like image 122
kennbrodhagen Avatar answered Sep 25 '22 21:09

kennbrodhagen