diff --git a/hcl2template/types.datasource.go b/hcl2template/types.datasource.go index c516627ed..3deab8c71 100644 --- a/hcl2template/types.datasource.go +++ b/hcl2template/types.datasource.go @@ -102,25 +102,10 @@ func (cfg *PackerConfig) startDatasource(dataSourceStore packer.DatasourceStore, }) } - // HACK: - // This is where we parse the variables being used in the data sources. - // By passing in the DatasourceContext variable, we tell the EvalContext - // that since this is a datasource being evaluated, we should not allow - // other data sources to be decoded into it. When secondaryEvaluation is - // true, we know that this data source needs another data source in order - // to be evaluated. So we instead retrieve a different EvalContext. - // This is a brute force method to enable data sources to depend on each - // other, and a more elegant solution will be available once we implement a - // true DAG for Packer. var decoded cty.Value var moreDiags hcl.Diagnostics body := block.Body - if secondaryEvaluation { - // LocalContext is a lie! See above. - decoded, moreDiags = decodeHCL2Spec(body, cfg.EvalContext(LocalContext, nil), datasource) - } else { - decoded, moreDiags = decodeHCL2Spec(body, cfg.EvalContext(DatasourceContext, nil), datasource) - } + decoded, moreDiags = decodeHCL2Spec(body, cfg.EvalContext(DatasourceContext, nil), datasource) diags = append(diags, moreDiags...) if moreDiags.HasErrors() { diff --git a/hcl2template/types.packer_config.go b/hcl2template/types.packer_config.go index cafe3b36b..0a2b1204c 100644 --- a/hcl2template/types.packer_config.go +++ b/hcl2template/types.packer_config.go @@ -118,18 +118,13 @@ func (cfg *PackerConfig) EvalContext(ctx BlockContext, variables map[string]cty. }, } - // Currently the places where you can make references to other blocks - // from one is very 'procedural', and in this specific case, we could make - // the data sources available to other datasources, but this would be - // order dependant, meaning that if you define two datasources in two - // different blocks, the second one can use the first one, but not the - // other way around; which would be totally confusing; so - for now - - // datasources can't use other datasources. // In the future we'd like to load and execute HCL blocks using a graph // dependency tree, so that any block can use any block whatever the // order. + // For now, don't add DataSources if there's a NilContext, which gets + // used with packer console. switch ctx { - case LocalContext, BuildContext: // todo: refine + case LocalContext, BuildContext, DatasourceContext: datasourceVariables, _ := cfg.Datasources.Values() ectx.Variables[dataAccessor] = cty.ObjectVal(datasourceVariables) }