Encoding & Decoding default variables
- Dominant language
- Go
- Stars
- 5.8k
- Forks
- 657
- Avg merge
- 20h 36m
- Merged PRs (30d)
- 6
Description
### HCL Template
How can I encode and decode a hcl file such like this?
```hcl
var "service_2_apis" {
default = [
{
api_name = "service-2-a",
endpoint = "/bye"
},
{
api_name = "service-2-b",
endpoint = "/brazile"
}
]
}
```
### Expected behavior
I am using `hclparse.ParseHCLFile` method for parsing a file.
```go
f, _ := p.Parser.ParseHCLFile(path)
var root schema.Root
decodeDiags := gohcl.DecodeBody(f.Body, nil, &root)
```
The `schema.Root` looks like this.
```go
type Root struct {
Resources []Resource `hcl:"resource,block"`
Variables []Variable `hcl:"var,block"`
}
type Resource struct {
Type string `hcl:"type,label"`
Name string `hcl:"name,label"`
}
type Variable struct {
Type string `hcl:"type,label"`
Default hcl.Expression `hcl:"default"`
}
```
How can I decode the HCL file?
And also I want to encode and generate a file like below. How can I generate this?
```hcl
var "service_2_apis" {
default = [
{
api_name = "service-2-a",
endpoint = "/bye"
},
{
api_name = "service-2-b",
endpoint = "/brazile"
}
]
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the gohcl.DecodeBody path and the APIs around hclparse.ParseHCLFile, using the provided Root and Variable schemas as the reproduction case. Determine whether decoding the default expression and generating the shown HCL are supported by existing APIs; done means a documented, tested path for both operations or a clearly scoped implementation request.
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
- 15/100