// Returns the list of targeted nodes. A targeted node is either addressed // directly, or is an Ancestor of a targeted node. Destroy mode keeps // Descendents instead of Ancestors. func (t *TargetsTransformer) selectTargetedNodes( g *Graph, addrs []ResourceAddress) (*dag.Set, error) { targetedNodes := new(dag.Set) for _, v := range g.Vertices() { if t.nodeIsTarget(v, addrs) { targetedNodes.Add(v) // We inform nodes that ask about the list of targets - helps for nodes // that need to dynamically expand. Note that this only occurs for nodes // that are already directly targeted. if tn, ok := v.(GraphNodeTargetable); ok { tn.SetTargets(addrs) } var deps *dag.Set var err error if t.Destroy { deps, err = g.Descendents(v) } else { deps, err = g.Ancestors(v) } if err != nil { return nil, err } for _, d := range deps.List() { targetedNodes.Add(d) } } } return targetedNodes, nil }
// Returns the list of targeted nodes. A targeted node is either addressed // directly, or is an Ancestor of a targeted node. Destroy mode keeps // Descendents instead of Ancestors. func (t *TargetsTransformer) selectTargetedNodes( g *Graph, addrs []ResourceAddress) (*dag.Set, error) { targetedNodes := new(dag.Set) for _, v := range g.Vertices() { if t.nodeIsTarget(v, addrs) { targetedNodes.Add(v) // We inform nodes that ask about the list of targets - helps for nodes // that need to dynamically expand. Note that this only occurs for nodes // that are already directly targeted. if tn, ok := v.(GraphNodeTargetable); ok { tn.SetTargets(addrs) } var deps *dag.Set var err error if t.Destroy { deps, err = g.Descendents(v) // Select any variables that we depend on in case we need them later for // interpolating in the count ancestors, _ := g.Ancestors(v) for _, a := range ancestors.List() { if _, ok := a.(*GraphNodeConfigVariableFlat); ok { deps.Add(a) } } } else { deps, err = g.Ancestors(v) } if err != nil { return nil, err } for _, d := range deps.List() { targetedNodes.Add(d) } } } return targetedNodes, nil }
func (t *TargetsTransformer) selectTargetedNodes( g *Graph, addrs []ResourceAddress) (*dag.Set, error) { targetedNodes := new(dag.Set) for _, v := range g.Vertices() { // Keep all providers; they'll be pruned later if necessary if r, ok := v.(GraphNodeProvider); ok { targetedNodes.Add(r) continue } // For the remaining filter, we only care about addressable nodes r, ok := v.(GraphNodeAddressable) if !ok { continue } if t.nodeIsTarget(r, addrs) { targetedNodes.Add(r) // If the node would like to know about targets, tell it. if n, ok := r.(GraphNodeTargetable); ok { n.SetTargets(addrs) } var deps *dag.Set var err error if t.Destroy { deps, err = g.Descendents(r) } else { deps, err = g.Ancestors(r) } if err != nil { return nil, err } for _, d := range deps.List() { targetedNodes.Add(d) } } } return targetedNodes, nil }