From cdde5cbbe2963753e549e27cf80d77f61c13f5d0 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 8 Oct 2021 11:33:52 -0700 Subject: [PATCH] fix source accessor to allow use in source block --- hcl2template/types.source.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hcl2template/types.source.go b/hcl2template/types.source.go index f877e7fad..e7ee39dae 100644 --- a/hcl2template/types.source.go +++ b/hcl2template/types.source.go @@ -110,6 +110,12 @@ func (cfg *PackerConfig) startBuilder(source SourceUseBlock, ectx *hcl.EvalConte } body := source.Body + // Add known values to source accessor in eval context. + ectx.Variables[sourcesAccessor] = cty.ObjectVal(map[string]cty.Value{ + "type": cty.StringVal(source.Type), + "name": cty.StringVal(source.Name), + }) + decoded, moreDiags := decodeHCL2Spec(body, ectx, builder) diags = append(diags, moreDiags...) if moreDiags.HasErrors() {