Parsing error tfvars to json
iamshinto opened this issue · 0 comments
iamshinto commented
Parsing error: tfvars to json:
terraform.tfvars:
ping_sg_cidr = {
1 = {
cidr_blocks = [
"0.0.0.0/0"
]
from_port = 8
to_port = -1
description = "Allow ping connections"
protocol = "icmp"
self = false
}
}
Current output:
{
"ping_sg_cidr": {
"1": {
"cidr_blocks": [
"0.0.0.0/0"
],
"from_port": 8,
"to_port": "${-1}",
"description": "Allow ping connections",
"protocol": "icmp",
"self": false
}
}
}
Expected output:
{
"ping_sg_cidr": {
"1": {
"cidr_blocks": [
"0.0.0.0/0"
],
"from_port": 8,
"to_port": -1,
"description": "Allow ping connections",
"protocol": "icmp",
"self": false
}
}
}
Python code:
import hcl2, json
with open('terraform.tfvars') as f:
print(json.dumps(hcl2.load(f), indent=2))