mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-19 14:31:40 -04:00
hcl2template: simplify startDatasource function
This commit is contained in:
committed by
Lucas Bajolet
parent
d9259d6d12
commit
51ec78622d
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/hashicorp/hcl/v2/hclsyntax"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
hcl2shim "github.com/hashicorp/packer/hcl2template/shim"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
@@ -65,13 +64,15 @@ func (ds *Datasources) Values() (map[string]cty.Value, hcl.Diagnostics) {
|
||||
return res, diags
|
||||
}
|
||||
|
||||
func (cfg *PackerConfig) startDatasource(dataSourceStore packer.DatasourceStore, ref DatasourceRef, secondaryEvaluation bool) (packersdk.Datasource, hcl.Diagnostics) {
|
||||
func (cfg *PackerConfig) startDatasource(ds DatasourceBlock) (packersdk.Datasource, hcl.Diagnostics) {
|
||||
var diags hcl.Diagnostics
|
||||
block := cfg.Datasources[ref].block
|
||||
block := ds.block
|
||||
|
||||
dataSourceStore := cfg.parser.PluginConfig.DataSources
|
||||
|
||||
if dataSourceStore == nil {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Summary: "Unknown " + dataSourceLabel + " type " + ref.Type,
|
||||
Summary: "Unknown " + dataSourceLabel + " type " + ds.Type,
|
||||
Subject: block.LabelRanges[0].Ptr(),
|
||||
Detail: "packer does not currently know any data source.",
|
||||
Severity: hcl.DiagError,
|
||||
@@ -79,9 +80,9 @@ func (cfg *PackerConfig) startDatasource(dataSourceStore packer.DatasourceStore,
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
if !dataSourceStore.Has(ref.Type) {
|
||||
if !dataSourceStore.Has(ds.Type) {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Summary: "Unknown " + dataSourceLabel + " type " + ref.Type,
|
||||
Summary: "Unknown " + dataSourceLabel + " type " + ds.Type,
|
||||
Subject: block.LabelRanges[0].Ptr(),
|
||||
Detail: fmt.Sprintf("known data sources: %v", dataSourceStore.List()),
|
||||
Severity: hcl.DiagError,
|
||||
@@ -89,7 +90,7 @@ func (cfg *PackerConfig) startDatasource(dataSourceStore packer.DatasourceStore,
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
datasource, err := dataSourceStore.Start(ref.Type)
|
||||
datasource, err := dataSourceStore.Start(ds.Type)
|
||||
if err != nil {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Summary: err.Error(),
|
||||
@@ -99,7 +100,7 @@ func (cfg *PackerConfig) startDatasource(dataSourceStore packer.DatasourceStore,
|
||||
}
|
||||
if datasource == nil {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Summary: fmt.Sprintf("failed to start datasource plugin %q.%q", ref.Type, ref.Name),
|
||||
Summary: fmt.Sprintf("failed to start datasource plugin %q.%q", ds.Type, ds.Name),
|
||||
Subject: &block.DefRange,
|
||||
Severity: hcl.DiagError,
|
||||
})
|
||||
|
||||
@@ -381,7 +381,7 @@ func (cfg *PackerConfig) recursivelyEvaluateDatasources(ref DatasourceRef, depen
|
||||
// If we've gotten here, then it means ref doesn't seem to have any further
|
||||
// dependencies we need to evaluate first. Evaluate it, with the cfg's full
|
||||
// data source context.
|
||||
datasource, startDiags := cfg.startDatasource(cfg.parser.PluginConfig.DataSources, ref, true)
|
||||
datasource, startDiags := cfg.startDatasource(ds)
|
||||
if startDiags.HasErrors() {
|
||||
diags = append(diags, startDiags...)
|
||||
return dependencies, diags
|
||||
|
||||
Reference in New Issue
Block a user