Skip to content

Commit

Permalink
correctly evaluate self in for_each resources
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbardin committed Oct 28, 2019
1 parent 62d75b5 commit fbc8cd1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lang/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit fbc8cd1

Please sign in to comment.