Inner double quotes parsed incorrectly
Closed this issue · 5 comments
Given a file using functions or accessing a key in a dictionary, where there are outer double quotes and inner double quotes around params, hcltojson does not properly parse the inner double quotes. Unfortunately, HCL seems not to allow single quotes at all to work around the problem.
example.tf:
resource "aws_iam_role" "child_instance_roles" {
count = "${length(split(",", var.child["instance_policy_paths"]))}"
name = "${element(split(",", var.child["instance_policy_names"]), count.index)}"
assume_role_policy = "${data.aws_iam_policy_document.ec2_assume_role.json}"
}
hcltojson example.tf
:
{
"resource": {
"aws_iam_role": {
"child_instance_roles": {
"count": "${length(split(",
", var": {
"child": {
"instance_policy_paths": {
"))}": {
"name": "${element(split(",
", var": {
"child": {
"instance_policy_names": {
"), count": {
"index)}": {
"assume_role_policy": "${data.aws_iam_policy_document.ec2_assume_role.json}"
}
}
}
}
}
}
}
}
}
}
}
}
}
Expected:
{
"resource": {
"aws_iam_role": {
"child_instance_roles": {
"count": "${length(split(\",\", var.child[\"instance_policy_paths\"]))}",
"name": "${element(split(\",\", var.child[\"instance_policy_names\"]), count.index)}",
"assume_role_policy": "${data.aws_iam_policy_document.ec2_assume_role.json}"
}
}
}
}
Thanks for reporting @lorengordon it's a valid bug but at the moment I don't know how should I fix this with in the current implementation, I'll take a look.
Npm version updated to 0.0.9
and published, also includes the example tf you've shared as a test input https://github.com/gokmen/hcl-to-json/blob/master/test/hcl-samples.coffee#L567-L573 --> https://github.com/gokmen/hcl-to-json/blob/master/test/hcl-samples-json.coffee#L607-L617 ,fyi.
Awesome! Thanks!
Hi @gokmen I believe this issue hasn't been 100% fixed. If you change the test added so that the split is done for " "
(a space) instead of ","
the tests break, which is similar to an issue we are experiencing.
Is there an easy fix for this?
Thanks!
Hi @abyx you're right and also there is a similar issue here #11 and my previous comment is still valid #5 (comment) It's hard to fix this problem with the current implementation and I don't have time for a fix for now. Patches are welcome for sure :)