hcl2template: intro and add UseSequential init opt

Following up on the DAG work, this commit adds a new option for
initialisation that disables DAG on request.

By default we are going to use the DAG approach, with an option to
fallback to using the older algorithm for evaluation in case users
end-up in an edge-case that prevents them from building a template.
pull/13197/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 56e08c2eff
commit 586762564b

@ -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)

@ -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 {

Loading…
Cancel
Save