diff --git a/lang/eval.go b/lang/eval.go index 989105f12be0..d27f44b21169 100644 --- a/lang/eval.go +++ b/lang/eval.go @@ -240,15 +240,17 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl // Self is an exception in that it must always resolve to a // particular instance. We will still insert the full resource into // the context below. + var hclDiags hcl.Diagnostics switch k := subj.Key.(type) { case addrs.IntKey: - self = val.Index(cty.NumberIntVal(int64(k))) + self, hclDiags = hcl.Index(val, cty.NumberIntVal(int64(k)), ref.SourceRange.ToHCL().Ptr()) + diags.Append(hclDiags) case addrs.StringKey: - self = val.Index(cty.StringVal(string(k))) + self, hclDiags = hcl.Index(val, cty.StringVal(string(k)), ref.SourceRange.ToHCL().Ptr()) + diags.Append(hclDiags) default: self = val } - continue }