hashicorp / hashicorp/hcl

[Question] How to allow arbitrary user defined values

Open
#599 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
5.8k
Forks
659
Avg merge
20h 36m
Merged PRs (30d)
6

Description

I'm creating a DSL using HCL, and bumping up against the ability to let users define a (mostly) arbitrary attribute.

Given an example HCL config like so:

example "resource_putter" {
  inputs = {
    foo = "foostring"
    bar = true
    buzz = vars.some_complex_value
  }
}

The values of the keys under inputs can effectively be anything. I can happily parse this into cty.Values, but I've not a found a non-janky way of getting that into an interface{} as I would with unknown json input, for example.

The exact syntax above is one example. I can flex within reason if there's some more supported way of handling this built-in. I could have inputs as a block, or change the structure in other ways if it makes it more feasible.

My main needs are that users can define a structure without having to template json strings (will be error prone and bad user experience), they should have access to the expression context and the top level keys will always be strings.

I've been bashing my head against this for over a day now and I'm basically out of ideas beyond recursively parsing the structure myself. That will work, but it seems others must have faced and solved this ahead of me.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the HCL expression and cty.Value handling described in the issue, especially how arbitrary values could preserve access to the expression context. Compare the requested inputs attribute with the suggested block structure and determine whether either has a supported representation in Go. Done means identifying and documenting a concrete supported approach, or confirming that custom recursive parsing is required.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.