diff --git a/terraform/transform_orphan_count.go b/terraform/transform_orphan_count.go index ab268ff38..029fa9a92 100644 --- a/terraform/transform_orphan_count.go +++ b/terraform/transform_orphan_count.go @@ -51,7 +51,8 @@ func (t *OrphanResourceCountTransformer) Transform(g *Graph) error { func (t *OrphanResourceCountTransformer) transformForEach(haveKeys map[addrs.InstanceKey]struct{}, g *Graph) error { // If there is a no-key node, add this to the graph first, - // because the last item determines the resource mode for the whole resource, + // so that we can create edges to it in subsequent (StringKey) nodes. + // This is because the last item determines the resource mode for the whole resource, // so if this (non-deterministically) happens to end up as the last one, // that will change the resource's EachMode and our addressing for our instances // will not work as expected @@ -79,6 +80,11 @@ func (t *OrphanResourceCountTransformer) transformForEach(haveKeys map[addrs.Ins } log.Printf("[TRACE] OrphanResourceCount(non-zero): adding %s as %T", t.Addr, node) g.Add(node) + + // Add edge to noKeyNode if it exists + if hasNoKeyNode { + g.Connect(dag.BasicEdge(node, noKeyNode)) + } } return nil }