terraform: encode module dependencies

This commit is contained in:
Armon Dadgar 2014-11-21 16:44:20 -08:00
parent ec1c026b80
commit 9c6280f64b
1 changed files with 56 additions and 31 deletions

View File

@ -303,18 +303,14 @@ func Graph(opts *GraphOpts) (*depgraph.Graph, error) {
// allows orphaned resources to be destroyed in the proper order. // allows orphaned resources to be destroyed in the proper order.
func graphEncodeDependencies(g *depgraph.Graph) { func graphEncodeDependencies(g *depgraph.Graph) {
for _, n := range g.Nouns { for _, n := range g.Nouns {
// Ignore any non-resource nodes switch rn := n.Meta.(type) {
rn, ok := n.Meta.(*GraphNodeResource) case *GraphNodeResource:
if !ok {
continue
}
r := rn.Resource
// If we are using create-before-destroy, there // If we are using create-before-destroy, there
// are some special depedencies injected on the // are some special depedencies injected on the
// deposed node that would cause a circular depedency // deposed node that would cause a circular depedency
// chain if persisted. We must only handle the new node, // chain if persisted. We must only handle the new node,
// node the deposed node. // node the deposed node.
r := rn.Resource
if r.Flags&FlagDeposed != 0 { if r.Flags&FlagDeposed != 0 {
continue continue
} }
@ -342,6 +338,35 @@ func graphEncodeDependencies(g *depgraph.Graph) {
// Update the dependencies // Update the dependencies
r.Dependencies = inject r.Dependencies = inject
case *GraphNodeModule:
// Update the dependencies
var inject []string
for _, dep := range n.Deps {
switch target := dep.Target.Meta.(type) {
case *GraphNodeModule:
if dep.Target.Name == n.Name {
continue
}
inject = append(inject, dep.Target.Name)
case *GraphNodeResource:
inject = append(inject, target.Resource.Id)
case *GraphNodeResourceProvider:
// Do nothing
default:
panic(fmt.Sprintf("Unknown graph node: %#v", dep.Target))
}
}
// Update the dependencies
if rn.State != nil {
rn.State.Dependencies = inject
}
}
} }
} }