4 "github.com/hashicorp/terraform/addrs"
5 "github.com/hashicorp/terraform/configs/configschema"
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 ConcreteResourceInstanceNodeFunc
15 Schema *configschema.Block
17 // Count is either the number of indexed instances to create, or -1 to
18 // indicate that count is not set at all and thus a no-key instance should
21 Addr addrs.AbsResource
24 func (t *ResourceCountTransformer) Transform(g *Graph) error {
26 // Negative count indicates that count is not set at all.
27 addr := t.Addr.Instance(addrs.NoKey)
29 abstract := NewNodeAbstractResourceInstance(addr)
30 abstract.Schema = t.Schema
31 var node dag.Vertex = abstract
32 if f := t.Concrete; f != nil {
40 // For each count, build and add the node
41 for i := 0; i < t.Count; i++ {
42 key := addrs.IntKey(i)
43 addr := t.Addr.Instance(key)
45 abstract := NewNodeAbstractResourceInstance(addr)
46 abstract.Schema = t.Schema
47 var node dag.Vertex = abstract
48 if f := t.Concrete; f != nil {