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.
This commit is contained in:
Martin Atkins 2018-05-29 16:27:30 -07:00
parent 68c8d83620
commit b6d0abef1d
1 changed files with 10 additions and 6 deletions

View File

@ -204,14 +204,18 @@ func (m *ReferenceMap) References(v dag.Vertex) ([]dag.Vertex, []addrs.Reference
for _, ref := range rn.References() { for _, ref := range rn.References() {
subject := ref.Subject subject := ref.Subject
// References may point to specific instances, but the resources may key := m.referenceMapKey(v, subject)
// not yet be expanded. Make sure we reference the resource type if _, exists := m.vertices[key]; !exists {
// itself. // 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 { if ri, ok := subject.(addrs.ResourceInstance); ok {
subject = ri.Resource subject = ri.Resource
key = m.referenceMapKey(v, subject)
}
} }
key := m.referenceMapKey(v, subject)
vertices := m.vertices[key] vertices := m.vertices[key]
for _, rv := range vertices { for _, rv := range vertices {
// don't include self-references // don't include self-references