Skip to content

Commit

Permalink
Merge pull request #5844 from hashicorp/b-hcl-parse-unknown-vars
Browse files Browse the repository at this point in the history
Upgrade hcl2 to validate arrays for unknown values
  • Loading branch information
Mahmood Ali committed Jun 19, 2019
2 parents e889377 + 9ebf0a7 commit e93bbf8
Show file tree
Hide file tree
Showing 15 changed files with 3,629 additions and 3,528 deletions.
47 changes: 47 additions & 0 deletions helper/pluginutils/hclutils/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,50 @@ func TestParseNullFields(t *testing.T) {
})
}
}

func TestParseUnknown(t *testing.T) {
spec := hclspec.NewObject(map[string]*hclspec.Spec{
"string_field": hclspec.NewAttr("string_field", "string", false),
"map_field": hclspec.NewAttr("map_field", "map(string)", false),
"list_field": hclspec.NewAttr("list_field", "map(string)", false),
"map_list_field": hclspec.NewAttr("map_list_field", "list(map(string))", false),
})
cSpec, diags := hclspecutils.Convert(spec)
require.False(t, diags.HasErrors())

cases := []struct {
name string
hcl string
}{
{
"string field",
`config { string_field = "${MYENV}" }`,
},
{
"map_field",
`config { map_field { key = "${MYENV}" }}`,
},
{
"list_field",
`config { list_field = ["${MYENV}"]}`,
},
{
"map_list_field",
`config { map_list_field { key = "${MYENV}"}}`,
},
}

vars := map[string]cty.Value{}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
inter := hclutils.HclConfigToInterface(t, c.hcl)

ctyValue, diag := hclutils.ParseHclInterface(inter, cSpec, vars)
t.Logf("parsed: %# v", pretty.Formatter(ctyValue))

require.True(t, diag.HasErrors())
require.Contains(t, diag.Errs()[0].Error(), "no variable named")
})
}
}
11 changes: 11 additions & 0 deletions vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e93bbf8

Please sign in to comment.