]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/terraform/terraform/transform_orphan_count.go
update vendor and go.mod
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / transform_orphan_count.go
index eec762e55af644dd4ea820e8ea07bc15ccc3c0e1..4f323a7a0ed20aedf2c0c0ee9035b53dc2842757 100644 (file)
@@ -6,6 +6,7 @@ import (
        "github.com/hashicorp/terraform/addrs"
        "github.com/hashicorp/terraform/dag"
        "github.com/hashicorp/terraform/states"
+       "github.com/zclconf/go-cty/cty"
 )
 
 // OrphanResourceCountTransformer is a GraphTransformer that adds orphans
@@ -18,9 +19,10 @@ import (
 type OrphanResourceCountTransformer struct {
        Concrete ConcreteResourceInstanceNodeFunc
 
-       Count int               // Actual count of the resource, or -1 if count is not set at all
-       Addr  addrs.AbsResource // Addr of the resource to look for orphans
-       State *states.State     // Full global state
+       Count   int                  // Actual count of the resource, or -1 if count is not set at all
+       ForEach map[string]cty.Value // The ForEach map on the resource
+       Addr    addrs.AbsResource    // Addr of the resource to look for orphans
+       State   *states.State        // Full global state
 }
 
 func (t *OrphanResourceCountTransformer) Transform(g *Graph) error {
@@ -34,6 +36,10 @@ func (t *OrphanResourceCountTransformer) Transform(g *Graph) error {
                haveKeys[key] = struct{}{}
        }
 
+       // if for_each is set, use that transformer
+       if t.ForEach != nil {
+               return t.transformForEach(haveKeys, g)
+       }
        if t.Count < 0 {
                return t.transformNoCount(haveKeys, g)
        }
@@ -43,6 +49,25 @@ func (t *OrphanResourceCountTransformer) Transform(g *Graph) error {
        return t.transformCount(haveKeys, g)
 }
 
+func (t *OrphanResourceCountTransformer) transformForEach(haveKeys map[addrs.InstanceKey]struct{}, g *Graph) error {
+       for key := range haveKeys {
+               s, _ := key.(addrs.StringKey)
+               // If the key is present in our current for_each, carry on
+               if _, ok := t.ForEach[string(s)]; ok {
+                       continue
+               }
+
+               abstract := NewNodeAbstractResourceInstance(t.Addr.Instance(key))
+               var node dag.Vertex = abstract
+               if f := t.Concrete; f != nil {
+                       node = f(abstract)
+               }
+               log.Printf("[TRACE] OrphanResourceCount(non-zero): adding %s as %T", t.Addr, node)
+               g.Add(node)
+       }
+       return nil
+}
+
 func (t *OrphanResourceCountTransformer) transformCount(haveKeys map[addrs.InstanceKey]struct{}, g *Graph) error {
        // Due to the logic in Transform, we only get in here if our count is
        // at least one.