bake: fix map type checking to detect matrix property set to list

Signed-off-by: Justin Chadwell <me@jedevc.com>
pull/1722/head
Justin Chadwell 2 years ago
parent a3293cdaaa
commit 9827abbf76

@ -820,7 +820,7 @@ func (t *Target) GetEvalContexts(ectx *hcl.EvalContext, block *hcl.Block, loadDe
return nil, err return nil, err
} }
if !value.CanIterateElements() { if !value.Type().IsMapType() && !value.Type().IsObjectType() {
return nil, errors.Errorf("matrix must be a map") return nil, errors.Errorf("matrix must be a map")
} }
matrix := value.AsValueMap() matrix := value.AsValueMap()

@ -1051,6 +1051,14 @@ func TestHCLMatrixBadTypes(t *testing.T) {
_, err := ParseFile(dt, "docker-bake.hcl") _, err := ParseFile(dt, "docker-bake.hcl")
require.Error(t, err) require.Error(t, err)
dt = []byte(`
target "default" {
matrix = ["test"]
}
`)
_, err = ParseFile(dt, "docker-bake.hcl")
require.Error(t, err)
dt = []byte(` dt = []byte(`
target "default" { target "default" {
matrix = { matrix = {
@ -1061,6 +1069,16 @@ func TestHCLMatrixBadTypes(t *testing.T) {
_, err = ParseFile(dt, "docker-bake.hcl") _, err = ParseFile(dt, "docker-bake.hcl")
require.Error(t, err) require.Error(t, err)
dt = []byte(`
target "default" {
matrix = {
1 = 2
}
}
`)
_, err = ParseFile(dt, "docker-bake.hcl")
require.Error(t, err)
dt = []byte(` dt = []byte(`
target "default" { target "default" {
matrix = { matrix = {

Loading…
Cancel
Save