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.
func graphEncodeDependencies(g *depgraph.Graph) {
for _, n := range g.Nouns {
// Ignore any non-resource nodes
rn, ok := n.Meta.(*GraphNodeResource)
if !ok {
continue
}
r := rn.Resource
switch rn := n.Meta.(type) {
case *GraphNodeResource:
// If we are using create-before-destroy, there
// are some special depedencies injected on the
// deposed node that would cause a circular depedency
// chain if persisted. We must only handle the new node,
// node the deposed node.
r := rn.Resource
if r.Flags&FlagDeposed != 0 {
continue
}
@ -342,6 +338,35 @@ func graphEncodeDependencies(g *depgraph.Graph) {
// Update the dependencies
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
}
}
}
}