@@ -225,14 +225,14 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl
225225 continue
226226 }
227227
228- // self can only be used within a resource instance
229- subj := selfAddr .(addrs.ResourceInstance )
230-
231228 if selfAddr == addrs .Self {
232229 // Programming error: the self address cannot alias itself.
233230 panic ("scope SelfAddr attempting to alias itself" )
234231 }
235232
233+ // self can only be used within a resource instance
234+ subj := selfAddr .(addrs.ResourceInstance )
235+
236236 val , valDiags := normalizeRefValue (s .Data .GetResource (subj .ContainingResource (), rng ))
237237
238238 diags = diags .Append (valDiags )
@@ -249,16 +249,16 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl
249249 self = val
250250 }
251251
252- r := subj .Resource
253- if managedResources [r .Type ] == nil {
254- managedResources [r .Type ] = make (map [string ]cty.Value )
255- }
256- managedResources [r.Type ][r.Name ] = val
257252 continue
258253 }
259254
260255 // This type switch must cover all of the "Referenceable" implementations
261- // in package addrs.
256+ // in package addrs, however we are removing the possibility of
257+ // ResourceInstance beforehand.
258+ if addr , ok := rawSubj .(addrs.ResourceInstance ); ok {
259+ rawSubj = addr .ContainingResource ()
260+ }
261+
262262 switch subj := rawSubj .(type ) {
263263 case addrs.Resource :
264264 var into map [string ]map [string ]cty.Value
@@ -280,27 +280,6 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl
280280 }
281281 into [r.Type ][r.Name ] = val
282282
283- case addrs.ResourceInstance :
284- var into map [string ]map [string ]cty.Value
285- switch subj .Resource .Mode {
286- case addrs .ManagedResourceMode :
287- into = managedResources
288- case addrs .DataResourceMode :
289- into = dataResources
290- default :
291- panic (fmt .Errorf ("unsupported ResourceMode %s" , subj .Resource .Mode ))
292- }
293-
294- val , valDiags := normalizeRefValue (s .Data .GetResource (subj .ContainingResource (), rng ))
295-
296- diags = diags .Append (valDiags )
297-
298- r := subj .Resource
299- if into [r .Type ] == nil {
300- into [r .Type ] = make (map [string ]cty.Value )
301- }
302- into [r.Type ][r.Name ] = val
303-
304283 case addrs.ModuleCallInstance :
305284 val , valDiags := normalizeRefValue (s .Data .GetModuleInstance (subj , rng ))
306285 diags = diags .Append (valDiags )
0 commit comments