terraform: move resource orphan deps out of loop

This commit is contained in:
Mitchell Hashimoto 2015-01-27 11:18:17 -08:00
parent 7025c48165
commit 98683b44b8
1 changed files with 13 additions and 4 deletions

View File

@ -26,10 +26,10 @@ func (t *OrphanTransformer) Transform(g *Graph) error {
} }
// Go over each resource orphan and add it to the graph. // Go over each resource orphan and add it to the graph.
for _, k := range state.Orphans(t.Config) { resourceOrphans := state.Orphans(t.Config)
g.ConnectTo( resourceVertexes := make([]dag.Vertex, len(resourceOrphans))
g.Add(&graphNodeOrphanResource{ResourceName: k}), for i, k := range resourceOrphans {
state.Resources[k].Dependencies) resourceVertexes[i] = g.Add(&graphNodeOrphanResource{ResourceName: k})
} }
// Go over each module orphan and add it to the graph. We store the // Go over each module orphan and add it to the graph. We store the
@ -42,6 +42,15 @@ func (t *OrphanTransformer) Transform(g *Graph) error {
moduleStates[i] = t.State.ModuleByPath(path) moduleStates[i] = t.State.ModuleByPath(path)
} }
// Now do the dependencies. We do this _after_ adding all the orphan
// nodes above because there are cases in which the orphans themselves
// depend on other orphans.
// Resource dependencies
for i, v := range resourceVertexes {
g.ConnectTo(v, state.Resources[resourceOrphans[i]].Dependencies)
}
// Module dependencies // Module dependencies
for i, v := range moduleVertexes { for i, v := range moduleVertexes {
g.ConnectTo(v, moduleStates[i].Dependencies) g.ConnectTo(v, moduleStates[i].Dependencies)