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 29, 2019
1 parent f11c836 commit fb7fc5e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lang/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit fb7fc5e

Please sign in to comment.