aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/terraform/transform_resource_count.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/transform_resource_count.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/terraform/transform_resource_count.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/transform_resource_count.go b/vendor/github.com/hashicorp/terraform/terraform/transform_resource_count.go
index 1123790..c70a3c1 100644
--- a/vendor/github.com/hashicorp/terraform/terraform/transform_resource_count.go
+++ b/vendor/github.com/hashicorp/terraform/terraform/transform_resource_count.go
@@ -4,6 +4,7 @@ import (
4 "github.com/hashicorp/terraform/addrs" 4 "github.com/hashicorp/terraform/addrs"
5 "github.com/hashicorp/terraform/configs/configschema" 5 "github.com/hashicorp/terraform/configs/configschema"
6 "github.com/hashicorp/terraform/dag" 6 "github.com/hashicorp/terraform/dag"
7 "github.com/zclconf/go-cty/cty"
7) 8)
8 9
9// ResourceCountTransformer is a GraphTransformer that expands the count 10// ResourceCountTransformer is a GraphTransformer that expands the count
@@ -17,12 +18,13 @@ type ResourceCountTransformer struct {
17 // Count is either the number of indexed instances to create, or -1 to 18 // 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 19 // indicate that count is not set at all and thus a no-key instance should
19 // be created. 20 // be created.
20 Count int 21 Count int
21 Addr addrs.AbsResource 22 ForEach map[string]cty.Value
23 Addr addrs.AbsResource
22} 24}
23 25
24func (t *ResourceCountTransformer) Transform(g *Graph) error { 26func (t *ResourceCountTransformer) Transform(g *Graph) error {
25 if t.Count < 0 { 27 if t.Count < 0 && t.ForEach == nil {
26 // Negative count indicates that count is not set at all. 28 // Negative count indicates that count is not set at all.
27 addr := t.Addr.Instance(addrs.NoKey) 29 addr := t.Addr.Instance(addrs.NoKey)
28 30
@@ -37,6 +39,19 @@ func (t *ResourceCountTransformer) Transform(g *Graph) error {
37 return nil 39 return nil
38 } 40 }
39 41
42 // Add nodes related to the for_each expression
43 for key := range t.ForEach {
44 addr := t.Addr.Instance(addrs.StringKey(key))
45 abstract := NewNodeAbstractResourceInstance(addr)
46 abstract.Schema = t.Schema
47 var node dag.Vertex = abstract
48 if f := t.Concrete; f != nil {
49 node = f(abstract)
50 }
51
52 g.Add(node)
53 }
54
40 // For each count, build and add the node 55 // For each count, build and add the node
41 for i := 0; i < t.Count; i++ { 56 for i := 0; i < t.Count; i++ {
42 key := addrs.IntKey(i) 57 key := addrs.IntKey(i)