Skip to content

hclwrite: add ObjectConsExpr.SetItemRaw() and ObjectConsExpr.ItemFor()#811

Draft
bbasata wants to merge 13 commits into
mainfrom
bbasata/rewrite-objects
Draft

hclwrite: add ObjectConsExpr.SetItemRaw() and ObjectConsExpr.ItemFor()#811
bbasata wants to merge 13 commits into
mainfrom
bbasata/rewrite-objects

Conversation

@bbasata

@bbasata bbasata commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Description

Rewrite object values.

config := []byte(`a = {
    hat = "derby", (cat) = "calico" }` + "\n")

bowler := hclwrite.TokensForValue(cty.StringVal(`bowler`))

file, _ := ParseConfig(config, "<inline>", hcl.Pos{})
attr := file.Body().GetAttribute("a")

expr := attr.Expr().AsObjectConsExpr()
key, value := expr.SetItemRaw("hat", bowler)

fmt.Printf("key: ")
key.BuildTokens(nil).WriteTo(os.Stdout)
fmt.Println()
fmt.Println("value: ")
value.BuildTokens(nil).WriteTo(os.Stdout)
fmt.Println()

Related Issue

#810

@bbasata bbasata force-pushed the bbasata/rewrite-objects branch from 460ef76 to 88a6bc4 Compare June 19, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant