diff --git a/hcl2template/types.datasource.go b/hcl2template/types.datasource.go index 765401bd4..42104c239 100644 --- a/hcl2template/types.datasource.go +++ b/hcl2template/types.datasource.go @@ -58,13 +58,13 @@ func (ds *DatasourceBlock) getDependencies() { ds.dependencies = dependencies } -const notReadyDataSourceError = "Dependencies not ready" +const NotReadyDataSourceError = "Dependencies not ready" // executed returns whether or not the datasource was executed // // Having a non-empty cty.Value object means this was filled-up after the // datasource has been executed, so this is what we use for this test. -func (ds DatasourceBlock) executed() bool { +func (ds DatasourceBlock) Executed() bool { return ds.value != cty.Value{} } @@ -89,7 +89,7 @@ func (ds *DatasourceBlock) Execute(cfg *PackerConfig, skipExecution bool) hcl.Di continue } - if !dep.executed() { + if !dep.Executed() { ok = false } } @@ -97,7 +97,7 @@ func (ds *DatasourceBlock) Execute(cfg *PackerConfig, skipExecution bool) hcl.Di if !ok { diags = append(diags, &hcl.Diagnostic{ Severity: hcl.DiagError, - Summary: notReadyDataSourceError, + Summary: NotReadyDataSourceError, Detail: "At least one dependency for the datasource is not executed already", Subject: &ds.block.DefRange, }) @@ -234,7 +234,7 @@ func (cfg *PackerConfig) startDatasource(ds DatasourceBlock) (packersdk.Datasour // datasourcesDone checks whether all the datasources have been executed or not func (cfg *PackerConfig) datasourcesDone() bool { for _, ds := range cfg.Datasources { - if !ds.executed() { + if !ds.Executed() { return false } } @@ -253,13 +253,13 @@ func (cfg *PackerConfig) executeDatasources(skipExecution bool) hcl.Diagnostics foundSomething := false outerDSEval: for _, ds := range cfg.Datasources { - if ds.executed() { + if ds.Executed() { continue } diags := ds.Execute(cfg, skipExecution) for _, diag := range diags { - if diag.Summary == notReadyDataSourceError { + if diag.Summary == NotReadyDataSourceError { // If we have a not ready error in the // datasource list, we should attempt to run the // rest, and eventually settle if we cannot move diff --git a/hcl2template/types.variables.go b/hcl2template/types.variables.go index 44dc51dc7..26c874c7f 100644 --- a/hcl2template/types.variables.go +++ b/hcl2template/types.variables.go @@ -77,7 +77,11 @@ func (local *LocalBlock) getDependencies() { local.dependencies = dependencies } -const varNotReadyForEval = "Local variable not ready for evaluation" +const VarNotReadyForEval = "Local variable not ready for evaluation" + +func (local LocalBlock) Evaluated() bool { + return local.evaluated +} func (local *LocalBlock) Evaluate(config *PackerConfig) hcl.Diagnostics { // No need to re-evaluate if already done @@ -94,7 +98,7 @@ func (local *LocalBlock) Evaluate(config *PackerConfig) hcl.Diagnostics { if config.LocalVariables[dep] == nil { return append(diags, &hcl.Diagnostic{ Severity: hcl.DiagError, - Summary: varNotReadyForEval, + Summary: VarNotReadyForEval, Detail: "Local variable local.%s is not ready yet to be evaluated as its dependencies are not ready yet.", }) } @@ -162,7 +166,7 @@ func (c *PackerConfig) evaluateLocalVariables() hcl.Diagnostics { // on the other variable blocks, until we reach a point where // we can evaluate it. if evalDiags.HasErrors() && - evalDiags[0].Summary == varNotReadyForEval { + evalDiags[0].Summary == VarNotReadyForEval { continue }