github.com/hs0210/hashicorp-terraform@v0.11.12-beta1/terraform/transform_count_boundary.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/dag"
     5  )
     6  
     7  // CountBoundaryTransformer adds a node that depends on everything else
     8  // so that it runs last in order to clean up the state for nodes that
     9  // are on the "count boundary": "foo.0" when only one exists becomes "foo"
    10  type CountBoundaryTransformer struct{}
    11  
    12  func (t *CountBoundaryTransformer) Transform(g *Graph) error {
    13  	node := &NodeCountBoundary{}
    14  	g.Add(node)
    15  
    16  	// Depends on everything
    17  	for _, v := range g.Vertices() {
    18  		// Don't connect to ourselves
    19  		if v == node {
    20  			continue
    21  		}
    22  
    23  		// Connect!
    24  		g.Connect(dag.BasicEdge(node, v))
    25  	}
    26  
    27  	return nil
    28  }