diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/transform_orphan_count.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/terraform/transform_orphan_count.go | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/transform_orphan_count.go b/vendor/github.com/hashicorp/terraform/terraform/transform_orphan_count.go index eec762e..4f323a7 100644 --- a/vendor/github.com/hashicorp/terraform/terraform/transform_orphan_count.go +++ b/vendor/github.com/hashicorp/terraform/terraform/transform_orphan_count.go | |||
@@ -6,6 +6,7 @@ import ( | |||
6 | "github.com/hashicorp/terraform/addrs" | 6 | "github.com/hashicorp/terraform/addrs" |
7 | "github.com/hashicorp/terraform/dag" | 7 | "github.com/hashicorp/terraform/dag" |
8 | "github.com/hashicorp/terraform/states" | 8 | "github.com/hashicorp/terraform/states" |
9 | "github.com/zclconf/go-cty/cty" | ||
9 | ) | 10 | ) |
10 | 11 | ||
11 | // OrphanResourceCountTransformer is a GraphTransformer that adds orphans | 12 | // OrphanResourceCountTransformer is a GraphTransformer that adds orphans |
@@ -18,9 +19,10 @@ import ( | |||
18 | type OrphanResourceCountTransformer struct { | 19 | type OrphanResourceCountTransformer struct { |
19 | Concrete ConcreteResourceInstanceNodeFunc | 20 | Concrete ConcreteResourceInstanceNodeFunc |
20 | 21 | ||
21 | Count int // Actual count of the resource, or -1 if count is not set at all | 22 | Count int // Actual count of the resource, or -1 if count is not set at all |
22 | Addr addrs.AbsResource // Addr of the resource to look for orphans | 23 | ForEach map[string]cty.Value // The ForEach map on the resource |
23 | State *states.State // Full global state | 24 | Addr addrs.AbsResource // Addr of the resource to look for orphans |
25 | State *states.State // Full global state | ||
24 | } | 26 | } |
25 | 27 | ||
26 | func (t *OrphanResourceCountTransformer) Transform(g *Graph) error { | 28 | func (t *OrphanResourceCountTransformer) Transform(g *Graph) error { |
@@ -34,6 +36,10 @@ func (t *OrphanResourceCountTransformer) Transform(g *Graph) error { | |||
34 | haveKeys[key] = struct{}{} | 36 | haveKeys[key] = struct{}{} |
35 | } | 37 | } |
36 | 38 | ||
39 | // if for_each is set, use that transformer | ||
40 | if t.ForEach != nil { | ||
41 | return t.transformForEach(haveKeys, g) | ||
42 | } | ||
37 | if t.Count < 0 { | 43 | if t.Count < 0 { |
38 | return t.transformNoCount(haveKeys, g) | 44 | return t.transformNoCount(haveKeys, g) |
39 | } | 45 | } |
@@ -43,6 +49,25 @@ func (t *OrphanResourceCountTransformer) Transform(g *Graph) error { | |||
43 | return t.transformCount(haveKeys, g) | 49 | return t.transformCount(haveKeys, g) |
44 | } | 50 | } |
45 | 51 | ||
52 | func (t *OrphanResourceCountTransformer) transformForEach(haveKeys map[addrs.InstanceKey]struct{}, g *Graph) error { | ||
53 | for key := range haveKeys { | ||
54 | s, _ := key.(addrs.StringKey) | ||
55 | // If the key is present in our current for_each, carry on | ||
56 | if _, ok := t.ForEach[string(s)]; ok { | ||
57 | continue | ||
58 | } | ||
59 | |||
60 | abstract := NewNodeAbstractResourceInstance(t.Addr.Instance(key)) | ||
61 | var node dag.Vertex = abstract | ||
62 | if f := t.Concrete; f != nil { | ||
63 | node = f(abstract) | ||
64 | } | ||
65 | log.Printf("[TRACE] OrphanResourceCount(non-zero): adding %s as %T", t.Addr, node) | ||
66 | g.Add(node) | ||
67 | } | ||
68 | return nil | ||
69 | } | ||
70 | |||
46 | func (t *OrphanResourceCountTransformer) transformCount(haveKeys map[addrs.InstanceKey]struct{}, g *Graph) error { | 71 | func (t *OrphanResourceCountTransformer) transformCount(haveKeys map[addrs.InstanceKey]struct{}, g *Graph) error { |
47 | // Due to the logic in Transform, we only get in here if our count is | 72 | // Due to the logic in Transform, we only get in here if our count is |
48 | // at least one. | 73 | // at least one. |