From fb7fc5e9189ef6e0de85e6a54a01d44c7acabb00 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 28 Oct 2019 15:36:04 -0400 Subject: [PATCH] correctly evaluate self in for_each resources The fallback type for GetResource from an EachMap is a cty.Object, because resource schemas may contain dynamically typed attributes. Check for an Object type in the evaluation of self, to use the proper GetAttr method when extracting the value. --- lang/eval.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 }