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.
This commit is contained in:
parent
f11c836181
commit
3839405d3d
10
lang/eval.go
10
lang/eval.go
|
@ -240,15 +240,19 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl
|
||||||
// Self is an exception in that it must always resolve to a
|
// Self is an exception in that it must always resolve to a
|
||||||
// particular instance. We will still insert the full resource into
|
// particular instance. We will still insert the full resource into
|
||||||
// the context below.
|
// the context below.
|
||||||
|
var hclDiags hcl.Diagnostics
|
||||||
|
// We should always have a valid self index by this point, but in
|
||||||
|
// the case of an error, self may end up as a cty.DynamicValue.
|
||||||
switch k := subj.Key.(type) {
|
switch k := subj.Key.(type) {
|
||||||
case addrs.IntKey:
|
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:
|
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:
|
default:
|
||||||
self = val
|
self = val
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue