Skip to content

Commit

Permalink
hcl2template: intro and add UseDAG init opt
Browse files Browse the repository at this point in the history
Following up on the DAG work, this commit adds a new option for
initialisation that enables DAG if required.

By default we are still going to use the current phased approach, so we
don't risk breaking existing configurations.

However, this option can then be exposed as a command-line flag for
people wanting to experiment with this evaluation technique and the
benefits it brings.
  • Loading branch information
lbajolet-hashicorp committed Aug 30, 2024
1 parent 581711d commit dbc4664
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions hcl2template/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,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.UseDAG {
diags = diags.Extend(cfg.evaluateBuildPrereqs(opts.SkipDatasourcesExecution))
} else {
diags = diags.Extend(cfg.evaluateDatasources(opts.SkipDatasourcesExecution))
diags = diags.Extend(cfg.evaluateLocalVariables(cfg.LocalBlocks))
}

filterVarsFromLogs(cfg.InputVariables)
filterVarsFromLogs(cfg.LocalVariables)
Expand Down
8 changes: 8 additions & 0 deletions packer/run_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// UseDAG 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.
UseDAG bool
}

type PluginBinaryDetector interface {
Expand Down

0 comments on commit dbc4664

Please sign in to comment.