ResourceAddr may have resources in LocalRef
This commit is contained in:
parent
f1e8aed48d
commit
dc393cc6e0
|
@ -83,16 +83,28 @@ func (r Reference) ModuleAddr() addrs.ModuleInstance {
|
||||||
// Because not all references belong to resources, the extra boolean return
|
// Because not all references belong to resources, the extra boolean return
|
||||||
// value indicates whether the returned address is valid.
|
// value indicates whether the returned address is valid.
|
||||||
func (r Reference) ResourceAddr() (addrs.AbsResource, bool) {
|
func (r Reference) ResourceAddr() (addrs.AbsResource, bool) {
|
||||||
switch addr := r.ContainerAddr.(type) {
|
moduleInstance := addrs.RootModuleInstance
|
||||||
|
|
||||||
|
switch container := r.ContainerAddr.(type) {
|
||||||
case addrs.ModuleInstance:
|
case addrs.ModuleInstance:
|
||||||
|
moduleInstance = container
|
||||||
|
|
||||||
|
switch ref := r.LocalRef.Subject.(type) {
|
||||||
|
case addrs.Resource:
|
||||||
|
return ref.Absolute(moduleInstance), true
|
||||||
|
case addrs.ResourceInstance:
|
||||||
|
return ref.ContainingResource().Absolute(moduleInstance), true
|
||||||
|
}
|
||||||
|
|
||||||
return addrs.AbsResource{}, false
|
return addrs.AbsResource{}, false
|
||||||
|
|
||||||
case addrs.AbsResourceInstance:
|
case addrs.AbsResourceInstance:
|
||||||
return addr.ContainingResource(), true
|
return container.ContainingResource(), true
|
||||||
default:
|
default:
|
||||||
// NOTE: We're intentionally using only a subset of possible
|
// NOTE: We're intentionally using only a subset of possible
|
||||||
// addrs.Targetable implementations here, so anything else
|
// addrs.Targetable implementations here, so anything else
|
||||||
// is invalid.
|
// is invalid.
|
||||||
panic(fmt.Sprintf("reference has invalid container address type %T", addr))
|
panic(fmt.Sprintf("reference has invalid container address type %T", container))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue