From b6d0abef1d5a79022cb5fbe1ce4e28eff50093ad Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 29 May 2018 16:27:30 -0700 Subject: [PATCH] core: Only treat instance ref as resource ref if instance nonexistent We previously added a special case for dealing with references to instances in the plan graph where there are only resource nodes. However, this was too general a fix and so it upset the handling of graphs where instances _are_ present. Now we'll do that fallback behavior only if there is no instance node in the graph already, so the exact matching behavior will be used in graphs where the instances are present. --- terraform/transform_reference.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/terraform/transform_reference.go b/terraform/transform_reference.go index 8b8f8f9d2..ff4092e6a 100644 --- a/terraform/transform_reference.go +++ b/terraform/transform_reference.go @@ -204,14 +204,18 @@ func (m *ReferenceMap) References(v dag.Vertex) ([]dag.Vertex, []addrs.Reference for _, ref := range rn.References() { subject := ref.Subject - // References may point to specific instances, but the resources may - // not yet be expanded. Make sure we reference the resource type - // itself. - if ri, ok := subject.(addrs.ResourceInstance); ok { - subject = ri.Resource + key := m.referenceMapKey(v, subject) + if _, exists := m.vertices[key]; !exists { + // If what we were looking for was a ResourceInstance then we + // might be in a resource-oriented graph rather than an + // instance-oriented graph, and so we'll see if we have the + // resource itself instead. + if ri, ok := subject.(addrs.ResourceInstance); ok { + subject = ri.Resource + key = m.referenceMapKey(v, subject) + } } - key := m.referenceMapKey(v, subject) vertices := m.vertices[key] for _, rv := range vertices { // don't include self-references