diff --git a/hcl2template/parser.go b/hcl2template/parser.go index 82372bac1..a11c5dd15 100644 --- a/hcl2template/parser.go +++ b/hcl2template/parser.go @@ -420,6 +420,10 @@ func (cfg *PackerConfig) buildPrereqsDAG() (*dag.AcyclicGraph, error) { } } + if err := retGraph.Validate(); err != nil { + return nil, err + } + return &retGraph, nil } diff --git a/internal/dag/dag.go b/internal/dag/dag.go index 118d4bf1b..e212135a8 100644 --- a/internal/dag/dag.go +++ b/internal/dag/dag.go @@ -127,13 +127,8 @@ func (g *AcyclicGraph) TransitiveReduction() { } } -// Validate validates the DAG. A DAG is valid if it has a single root -// with no cycles. +// Validate validates the DAG. A DAG is valid if it has no cycles or self-referencing vertex. func (g *AcyclicGraph) Validate() error { - if _, err := g.Root(); err != nil { - return err - } - // Look for cycles of more than 1 component var err error cycles := g.Cycles()