Closed tamalsaha closed 4 years ago
HCL is already JSON compatible so I am not sure the issue you are running into. It would be good to see what a generated policy looks like to help identify the issue.
For example: config1:
listener "tcp" {
address = "0.0.0.0:8200"
}
storage "file" {
path = "/home/ac/go/src/github.com/kubevault/hq/dist/vault/data"
}
disable_mlock= true
ui = true
config2:
listener "tcp" {
address = "127.0.0.1:8200"
}
After merge operation: mergedJson:
{
"disable_mlock": true,
"listener": [
{
"tcp": [
{
"address": "127.0.0.1:8200"
}
]
}
],
"storage": [
{
"file": [
{
"path": "/home/ac/go/src/github.com/kubevault/hq/dist/vault/data"
}
]
}
],
"ui": true
}
mergedHcl:
"disable_mlock" = true
"listener" = {
"tcp" = {
"address" = "127.0.0.1:8200"
}
}
"storage" = {
"file" = {
"path" = "/home/ac/go/src/github.com/kubevault/hq/dist/vault/data"
}
}
"ui" = true
I'm not sure what you're using to convert but it's making the storage block into an array. It should be a straight dict.
github.com/hashicorp/hcl
this library to Unmarshal hcl into map[string]interface{}
.github.com/appscode/mergo
this library to merge the maps.json.Marshal()
to get json of the merged maps.github.com/hashicorp/hcl/json/parser
to parse the json .github.com/hashicorp/hcl/hcl/printer
to write ast in file.
code can be found here https://github.com/kubevault/hq/blob/mrg/main.go#L50There are no plans that I'm currently aware of to support HCL2. That doesn't mean it won't happen, just that it's not high on the priority list. I'm going to close this for now, as I don't see that there's much for us to do here.
I curious to know what are the plans for supporting HCL2 in Vault? If yes, is there a tentative timeline (6 months? 1 yr?) for that?
My use-case is that I want to overwrite a HCL file with another HCL file. Currently I am trying to do that by converting them to Json, then overwrite in json format and then convert back to HCL. Unfortunately Vault rejects the merged json/hcl format. Given HCL2 will be 1-1 with Json, this problem should go away.