2016-09-19 18:28:24 +02:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
2018-08-27 21:03:20 +02:00
|
|
|
"github.com/hashicorp/terraform/configs"
|
2016-09-19 18:28:24 +02:00
|
|
|
"github.com/hashicorp/terraform/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"
|
2018-08-27 21:03:20 +02:00
|
|
|
type CountBoundaryTransformer struct {
|
|
|
|
Config *configs.Config
|
|
|
|
}
|
2016-09-19 18:28:24 +02:00
|
|
|
|
|
|
|
func (t *CountBoundaryTransformer) Transform(g *Graph) error {
|
2018-08-27 21:03:20 +02:00
|
|
|
node := &NodeCountBoundary{
|
|
|
|
Config: t.Config,
|
|
|
|
}
|
2016-09-19 18:28:24 +02:00
|
|
|
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
|
|
|
|
}
|