Skip to content

Commit

Permalink
Fallback to raw values in object attributes (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlObolenski authored Sep 4, 2024
1 parent 5857aee commit 8027023
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions hcledit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,20 @@ attribute = local.var
},
},

"fallback to absolute variable name in object": {
input: `
object = {
attribute = local.var
}
`,
options: []hcledit.Option{hcledit.WithReadFallbackToRawString()},
expectErr: true,
query: "object.attribute",
want: map[string]interface{}{
"object.attribute": "local.var",
},
},

"fallback to uninterpolated string": {
input: `
attribute = "some-${local.var}"
Expand Down
5 changes: 3 additions & 2 deletions internal/handler/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func (h *readHandler) HandleBody(body *hclwrite.Body, name string, keyTrail []st

func (h *readHandler) HandleObject(object *ast.Object, name string, keyTrail []string) error {
buf := object.GetObjectAttribute(name).BuildTokens().Bytes()
value, err := parse(buf, name, h.fallbackToRawString)
if err != nil {
fallback := h.fallbackToRawString
value, err := parse(buf, name, fallback)
if err != nil && !fallback {
return err
}
h.results[strings.Join(keyTrail, ".")] = value
Expand Down

0 comments on commit 8027023

Please sign in to comment.