From dc393cc6e0c65e6c5577e58e7da4815a90f04cf6 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 4 Feb 2022 12:39:08 -0500 Subject: [PATCH] ResourceAddr may have resources in LocalRef --- internal/lang/globalref/reference.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/lang/globalref/reference.go b/internal/lang/globalref/reference.go index 71920c304..47f48c3c8 100644 --- a/internal/lang/globalref/reference.go +++ b/internal/lang/globalref/reference.go @@ -83,16 +83,28 @@ func (r Reference) ModuleAddr() addrs.ModuleInstance { // Because not all references belong to resources, the extra boolean return // value indicates whether the returned address is valid. func (r Reference) ResourceAddr() (addrs.AbsResource, bool) { - switch addr := r.ContainerAddr.(type) { + moduleInstance := addrs.RootModuleInstance + + switch container := r.ContainerAddr.(type) { 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 + case addrs.AbsResourceInstance: - return addr.ContainingResource(), true + return container.ContainingResource(), true default: // NOTE: We're intentionally using only a subset of possible // addrs.Targetable implementations here, so anything else // is invalid. - panic(fmt.Sprintf("reference has invalid container address type %T", addr)) + panic(fmt.Sprintf("reference has invalid container address type %T", container)) } }