github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/transform_proxy.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/dag"
     5  )
     6  
     7  // GraphNodeProxy must be implemented by nodes that are proxies.
     8  //
     9  // A node that is a proxy says that anything that depends on this
    10  // node (the proxy), should also copy all the things that the proxy
    11  // itself depends on. Example:
    12  //
    13  //    A => proxy => C
    14  //
    15  // Should transform into (two edges):
    16  //
    17  //    A => proxy => C
    18  //    A => C
    19  //
    20  // The purpose for this is because some transforms only look at direct
    21  // edge connections and the proxy generally isn't meaningful in those
    22  // situations, so we should complete all the edges.
    23  type GraphNodeProxy interface {
    24  	Proxy() bool
    25  }
    26  
    27  // ProxyTransformer is a transformer that goes through the graph, finds
    28  // vertices that are marked as proxies, and connects through their
    29  // dependents. See above for what a proxy is.
    30  type ProxyTransformer struct{}
    31  
    32  func (t *ProxyTransformer) Transform(g *Graph) error {
    33  	for _, v := range g.Vertices() {
    34  		pn, ok := v.(GraphNodeProxy)
    35  		if !ok {
    36  			continue
    37  		}
    38  
    39  		// If we don't want to be proxies, don't do it
    40  		if !pn.Proxy() {
    41  			continue
    42  		}
    43  
    44  		// Connect all the things that depend on this to things that
    45  		// we depend on as the proxy. See docs for GraphNodeProxy for
    46  		// a visual explanation.
    47  		for _, s := range g.UpEdges(v).List() {
    48  			for _, t := range g.DownEdges(v).List() {
    49  				g.Connect(GraphProxyEdge{
    50  					Edge: dag.BasicEdge(s, t),
    51  				})
    52  			}
    53  		}
    54  	}
    55  
    56  	return nil
    57  }
    58  
    59  // GraphProxyEdge is the edge that is used for proxied edges.
    60  type GraphProxyEdge struct {
    61  	dag.Edge
    62  }