hashicorp / hashicorp/hcl

is there a way to assign values to fields of the root object?

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

Description

### HCL Template
```hcl
builders {
type = "docker"
image = "golang"
export_path = "image.tar"
commit = true
changes = [
"WORKDIR /bwaf",
"LABEL timestamp {{ timestamp }}",
]
}

provisioners {
type = "file"
source = "."
destination = "/tmp/git"
}

provisioners {
type = "converge"
module = "/tmp/git/converge.hcl"
bootstrap = true
prevent_bootstrap_sudo = true
prevent_sudo = true
bootstrap_command = "curl -k https://get.converge.sh | {{if .Sudo}}sudo {{end}}sh {{if ne .Version \"\"}}-s -- -v {{.Version}}{{end}}"
}
provisioners {
type = "shell"
inline = [
"rm -rf /tmp/git /usr/local/bin/converge",
]
}

"variables" = {
a=1
}
```
`$ json2hcl -reverse < packer.hcl`
```json
{
"builders": [
{
"changes": [
"WORKDIR /bwaf",
"LABEL commit {{ user `git_sha` }}",
"LABEL timestamp {{ timestamp }}"
],
"commit": true,
"export_path": "image.tar",
"image": "golang",
"type": "docker"
}
],
"provisioners": [
{
"destination": "/tmp/git",
"source": ".",
"type": "file"
}
],
"variables": [
{
"a": 1
}
]
}
```

### ~Expected~ desired behavior
get back json containing: `..."variables":{"a":1}`

### Actual behavior
the stuff i understood to happen based on my tf/nomad usage; building lists of objects.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the json2hcl -reverse command and trace how the root-level "variables" block is decoded and rendered. Compare the current output with the desired object form shown in the issue, then verify that nested list-of-object handling still works and that reverse conversion produces "variables":{"a":1}.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.