hashicorp / hashicorp/hcl

Allow for block types with optional labels

Open
#666 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

For [couper](https://github.com/coupergateway/couper/) we use an hcl-based configuration language. The language defines some block types that have optional labels, e.g.:
```hcl
api {
}
api "my_api" {
}
```
are both valid. (In this configuration language there are no block types with more than one label.)

We implemented this in a [fork](https://github.com/coupergateway/hcl) by allowing a third token `optional` following `label`, e.g.

```go
type API struct {
// ...
Name string `hcl:"name,label,optional"`
// ...
}
```
, which is not conformant with [gohcl/doc.go](https://github.com/hashicorp/hcl/blob/57f8bbf184a628a6dedb36520db1c90bfab7fb06/gohcl/doc.go#L15):
```
// Within each tag there are two comma-separated tokens. The first is the
// name of the corresponding construct in configuration, while the second
// is a keyword giving the kind of construct expected.
```
. (We could also have used another "second" token, like `optional_label`, to get the same effect, though.)

Do you think this may be of use for other hcl-based languages as well?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with gohcl/doc.go and compare the proposed tag syntax with the linked Couper fork. Trace how label tags are parsed and validated, then determine the expected behavior for blocks with and without labels. Done means optional labels are supported without changing existing required-label behavior, with tests covering both examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.