hcl2.load() reading list as string
angangwa opened this issue · comments
Anirudh Gangwal commented
Strings are being read as List of strings. Similar to an older issue - but updating library to latest version didn't help. Details below.
python-hcl2: Version 4.0.0
lark-parser: Version 0.10.1
# terraform.tfvars file
environment = "dev"
aws_region = "eu-west-2"
# Loading hcl file with Python
with open(config_to_import, "r", encoding="utf-8") as file:
content = hcl2.load(file)
logger.info("TF vars read: %s", json.dumps(content, indent=4))
Output:
INFO: [***] TF vars read: {
"environment": [
"dev"
],
"aws_region": [
"eu-west-2"
]
}
Expected output:
INFO: [***] TF vars read: {
"environment": "dev",
"aws_region": "eu-west-2"
}
George Torianik commented
For me v4.2.0 works. Please, try to upgrade.
$ git describe --abbrev=0 --tags
v4.2.0
$ pip freeze | grep "lark"
lark==1.1.5
lark-parser==0.10.1
$ cat > terraform.tfvars << EOF
environment = "dev"
aws_region = "eu-west-2"
EOF
$ python3
>>> import hcl2
>>> with open("terraform.tfvars", "r", encoding="utf-8") as file:
... hcl2.load(file)
...
{'environment': 'dev', 'aws_region': 'eu-west-2'}