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