diff --git a/hcl2template/parser.go b/hcl2template/parser.go index 1c3430dea..82372bac1 100644 --- a/hcl2template/parser.go +++ b/hcl2template/parser.go @@ -474,8 +474,13 @@ func (cfg *PackerConfig) evaluateBuildPrereqs(skipDatasources bool) hcl.Diagnost func (cfg *PackerConfig) Initialize(opts packer.InitializeOptions) hcl.Diagnostics { diags := cfg.InputVariables.ValidateValues() - diags = append(diags, cfg.evaluateDatasources(opts.SkipDatasourcesExecution)...) - diags = append(diags, cfg.evaluateLocalVariables(cfg.LocalBlocks)...) + + if opts.UseSequential { + diags = diags.Extend(cfg.evaluateDatasources(opts.SkipDatasourcesExecution)) + diags = diags.Extend(cfg.evaluateLocalVariables(cfg.LocalBlocks)) + } else { + diags = diags.Extend(cfg.evaluateBuildPrereqs(opts.SkipDatasourcesExecution)) + } filterVarsFromLogs(cfg.InputVariables) filterVarsFromLogs(cfg.LocalVariables) diff --git a/packer/run_interfaces.go b/packer/run_interfaces.go index 07829e629..3b7170899 100644 --- a/packer/run_interfaces.go +++ b/packer/run_interfaces.go @@ -38,6 +38,14 @@ type InitializeOptions struct { // When set, the execution of datasources will be skipped and the datasource will provide // an output spec that will be used for validation only. SkipDatasourcesExecution bool + // UseSequential changes the way data sources and locals are evaluated. + // + // In this mode, instead of using two separate phases to evaluate datasources first, then + // local variables, here we instead use a DAG so both are evaluated at once, based on the + // dependencies between them. + // + // This is optional and defaults to false for now, but this may become a default later. + UseSequential bool } type PluginBinaryDetector interface {