Skip to content

Commit

Permalink
Merge branch 'main' into katcipis-integrate-condition-on-generate
Browse files Browse the repository at this point in the history
  • Loading branch information
katcipis authored Jun 3, 2022
2 parents c7596cb + 6a76141 commit 15b7bb7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 1 addition & 2 deletions hcl/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"io/ioutil"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/mineiros-io/terramate/errors"
Expand Down Expand Up @@ -98,7 +97,7 @@ func (c *Context) PartialEval(expr hclsyntax.Expression) (hclwrite.Tokens, error

exprRange := expr.Range()
exprBytes := filedata[exprRange.Start.Byte:exprRange.End.Byte]
tokens, diags := hclsyntax.LexExpression(exprBytes, exprFname, hcl.Pos{})
tokens, diags := hclsyntax.LexExpression(exprBytes, exprFname, hhcl.Pos{})
if diags.HasErrors() {
return nil, errors.E(diags, "failed to scan expression")
}
Expand Down
12 changes: 6 additions & 6 deletions hcl/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ func fmtNextElement(tokens hclwrite.Tokens) (hclwrite.Tokens, int) {
}

func fmtAnyExpr(tokens hclwrite.Tokens) (hclwrite.Tokens, int) {
// this function expects that `tokens` are inside a `[` token.
// It works for either list elements or indexing.
// eg.:
// list = [<tokens>
// list = [1, 2, <tokens>
// value = ["foo", "bar"][<tokens
// this function expects that `tokens` are inside a `[` token.
// It works for either list elements or indexing.
// eg.:
// list = [<tokens>
// list = [1, 2, <tokens>
// value = ["foo", "bar"][<tokens
// We may have brackets inside expr, so closing bracket
// may not indicate end of the surrounding list reached.
openBrackets := 0
Expand Down
2 changes: 1 addition & 1 deletion test/hclwrite/hclwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (b *Block) AddNumberInt(name string, v int64) {
// AddString adds string on block.
func (b *Block) AddString(name string, v string) {
b.ctyvalues[name] = cty.StringVal(v)
b.addAttr(name, fmt.Sprintf("%q", v))
b.addAttr(name, fmt.Sprintf(`"%s"`, v))
}

// AddBoolean adds boolean on block.
Expand Down
11 changes: 11 additions & 0 deletions test/hclwrite/hclwrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ func TestHCLWrite(t *testing.T) {
}
`,
},
{
name: "string contents are not quoted",
hcl: block("test",
str("str", `THIS IS ${tm_upper(global.value) + "test"} !!!`),
),
want: `
test {
str = "THIS IS ${tm_upper(global.value) + "test"} !!!"
}
`,
},
{
name: "block with multiple attributes",
hcl: block("test",
Expand Down

0 comments on commit 15b7bb7

Please sign in to comment.