diff --git a/bake/bake.go b/bake/bake.go index fc6032f2..e8073202 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -820,7 +820,7 @@ func (t *Target) GetEvalContexts(ectx *hcl.EvalContext, block *hcl.Block, loadDe return nil, err } - if !value.CanIterateElements() { + if !value.Type().IsMapType() && !value.Type().IsObjectType() { return nil, errors.Errorf("matrix must be a map") } matrix := value.AsValueMap() diff --git a/bake/hcl_test.go b/bake/hcl_test.go index 5010984c..dedde357 100644 --- a/bake/hcl_test.go +++ b/bake/hcl_test.go @@ -1051,6 +1051,14 @@ func TestHCLMatrixBadTypes(t *testing.T) { _, err := ParseFile(dt, "docker-bake.hcl") require.Error(t, err) + dt = []byte(` + target "default" { + matrix = ["test"] + } + `) + _, err = ParseFile(dt, "docker-bake.hcl") + require.Error(t, err) + dt = []byte(` target "default" { matrix = { @@ -1061,6 +1069,16 @@ func TestHCLMatrixBadTypes(t *testing.T) { _, err = ParseFile(dt, "docker-bake.hcl") require.Error(t, err) + dt = []byte(` + target "default" { + matrix = { + 1 = 2 + } + } + `) + _, err = ParseFile(dt, "docker-bake.hcl") + require.Error(t, err) + dt = []byte(` target "default" { matrix = {