github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/transform_count_boundary.go (about)

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