This module essentially converts tfvars file to json file.
Where possible, Terraform automatically converts values from one type to another in order to produce the expected type. If this isn't possible, Terraform will produce a type mismatch error and you must update the configuration with a more suitable expression. Terraform automatically converts number and bool values to strings when needed. It also converts strings to numbers or bools, as long as the string contains a valid representation of a number or bool value.
true
converts to"true"
, and vice-versafalse
converts to"false"
, and vice-versa15
converts to"15"
, and vice-versa
The module doesn't handlke this type conversion, it spits out json with tfvar contents as is. the output json file is of same name as the input tfvar file.
input -> test.tfvars
var = val
output -> test.json
{
var = val
}
Note: The GO version already exists: alisdair/tfvars-json
Apparently there is a python library as well. amplify-education/python-hcl2
USAGEimport json import hcl2 with open('foo.tf', 'r') as file: dict = hcl2.load(file) with open("foo.json", "w") as file_out: file_out.write(json.dumps(dict, indent=4))