From fbc8cd18add2591dc674c5c138ed6266a7ecb741 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lang/eval.go b/lang/eval.go index 989105f12be0..9cd125c51754 100644 --- a/lang/eval.go +++ b/lang/eval.go @@ -244,11 +244,17 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl case addrs.IntKey: self = val.Index(cty.NumberIntVal(int64(k))) case addrs.StringKey: - self = val.Index(cty.StringVal(string(k))) + switch { + case val.Type().IsMapType(): + self = val.Index(cty.StringVal(string(k))) + case val.Type().IsObjectType(): + self = val.GetAttr(string(k)) + default: + panic(fmt.Sprintf("unexpected value type: %#v", val.Type())) + } default: self = val } - continue }