opentofu/internal/terraform/transform_count_boundary.go
Martin Atkins 36d0a50427 Move terraform/ to internal/terraform/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

34 lines
735 B
Go

package terraform
import (
"github.com/hashicorp/terraform/internal/configs"
"github.com/hashicorp/terraform/internal/dag"
)
// CountBoundaryTransformer adds a node that depends on everything else
// so that it runs last in order to clean up the state for nodes that
// are on the "count boundary": "foo.0" when only one exists becomes "foo"
type CountBoundaryTransformer struct {
Config *configs.Config
}
func (t *CountBoundaryTransformer) Transform(g *Graph) error {
node := &NodeCountBoundary{
Config: t.Config,
}
g.Add(node)
// Depends on everything
for _, v := range g.Vertices() {
// Don't connect to ourselves
if v == node {
continue
}
// Connect!
g.Connect(dag.BasicEdge(node, v))
}
return nil
}