From 3662dbc03d53747cb8a94b9bd428c7afba60b44f Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Tue, 13 Aug 2019 10:10:36 -0400 Subject: [PATCH] Ensure no key added to graph first --- terraform/transform_orphan_count.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/terraform/transform_orphan_count.go b/terraform/transform_orphan_count.go index 4f323a7a0..ab268ff38 100644 --- a/terraform/transform_orphan_count.go +++ b/terraform/transform_orphan_count.go @@ -50,6 +50,16 @@ 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 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 + noKeyNode, hasNoKeyNode := haveKeys[addrs.NoKey] + if hasNoKeyNode { + g.Add(noKeyNode) + } + for key := range haveKeys { s, _ := key.(addrs.StringKey) // If the key is present in our current for_each, carry on @@ -57,6 +67,11 @@ func (t *OrphanResourceCountTransformer) transformForEach(haveKeys map[addrs.Ins continue } + // If the key is no-key, we have already added it, so skip + if key == addrs.NoKey { + continue + } + abstract := NewNodeAbstractResourceInstance(t.Addr.Instance(key)) var node dag.Vertex = abstract if f := t.Concrete; f != nil {