-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling escaped characters when converting json to hcl #7
Comments
Are these escape characters in the resulting HCL harmful and cause it to be invalid or is it just an aesthetic concern? |
The resulting HCL is invalid. |
I have debugged this issue a bit and, if it's a bug, it originates in Hashicorp's HCL library (https://github.com/hashicorp/hcl). Since I am not well versed in HCL on my own, could you explain to me when a double quote needs to be escaped in HCL? Only when it's not inside a |
I'm on holiday this week and can't really test or research further as i don't have a computer. However, I cannot recall needing to escape double quotes at all in any of the HCL templates I've written. |
I've similar issue with my own automated tool that generates JSON configuration. Here is the generated configuration: {
"resource":[
{
"bitbucket_hook":{
"bamboo":{
"events":[
"repo:push",
"pullrequest:fulfilled"
],
"url":"${format(var.bamboo_url, \"PRJ-KEY\", var.skip_branches ? \"true\" : \"false\")}",
"description":"Trigger Bamboo build: PRJ-KEY",
"owner":"${var.owner}",
"repository":"${bitbucket_repository.PRJ-KEY}"
}
}
}
]
} This configuration is converted to: "resource" "bitbucket_hook" "bamboo" {
"events" = ["repo:push", "pullrequest:fulfilled"]
"url" = "${format(var.bamboo_url, \"PRJ-KEY\", var.skip_branches ? \"true\" : \"false\")}"
"description" = "Trigger Bamboo build: PRJ-KEY"
"owner" = "${var.owner}"
"repository" = "${bitbucket_repository.PRJ-KEY}"
} As you can see, the arguments for the "url" = "${format(var.bamboo_url, "PRJ-KEY", var.skip_branches ? "true" : "false")}" |
To be honest, I don't know HCL that well. Is |
Sorry, should've made that clear: yes, it's not a valid HCL. |
This seems to be a problem in the upstream HCL package we use. So I reported the error there: hashicorp/hcl#268. However, this has already been reported but there was no further activity: hashicorp/hcl#233 |
When using functions where arguments are wrapped in double quotes, so there are both outer double quotes around the variable syntax and inner double quotes around the values, json2hcl handles the hcl to json part fine (other than the extra arrays already reported in a different issue), but when converting that json back to hcl the escape characters are not removed.
example.tf:
cat example.tf | json2hcl -reverse
:cat example.tf | json2hcl -reverse | json2hcl
:The text was updated successfully, but these errors were encountered: