6 "github.com/hashicorp/terraform/dag"
9 // ResourceCountTransformer is a GraphTransformer that expands the count
10 // out for a specific resource.
12 // This assumes that the count is already interpolated.
13 type ResourceCountTransformer struct {
14 Concrete ConcreteResourceNodeFunc
20 func (t *ResourceCountTransformer) Transform(g *Graph) error {
21 // Don't allow the count to be negative
23 return fmt.Errorf("negative count: %d", t.Count)
26 // For each count, build and add the node
27 for i := 0; i < t.Count; i++ {
28 // Set the index. If our count is 1 we special case it so that
29 // we handle the "resource.0" and "resource" boundary properly.
35 // Build the resource address
39 // Build the abstract node and the concrete one
40 abstract := &NodeAbstractResource{
43 var node dag.Vertex = abstract
44 if f := t.Concrete; f != nil {
48 // Add it to the graph