hcl
hcl copied to clipboard
Decode blocks into map with custom struct types
HCLv2 gohcl supports parsing labeled blocks into slices (e.g. []customStruct). This adds support for decoding labeled blocks into map types (e.g. map[string]customStruct), with the additional constraint that labels are unique.
We special case single labeled blocks, as the behavior for multi labeled blocks is not well scoped.
This i s motivated by some map typed fields in Nomad structure (like TaskGroup.Volumes, and ConsulGatewayProxy. EnvoyGatewayBindAddresses. While I suspect this is of wider benefit, I understand if the use case is deemed to narrow to include into the base gohcl library.
Concretely, assuming a type Policies map[string]customStruct 'hcl:"policy,block"', the following hcl declaration
policy "foo" {
val = "a"
}
policy "bar" {
val = "b"
}
is decoded as
map[string}*customStruct{
"foo": &customStruct{Val: "a"},
"bar": &customStruct{Val: "b"},
}
Is there any movement on this PR? I have a need for supporting labeled blocks, and the workaround is... ugly.
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement
Learn more about why HashiCorp requires a CLA and what the CLA includes
Mahmood Ali seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you already have a GitHub account, please add the email address used for this commit to your account.
Have you signed the CLA already but the status is still pending? Recheck it.