]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/terraform/terraform/eval_diff.go
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / eval_diff.go
index c35f9083f89cefcdd162e17c05596ec31da720ce..26205ce51ec3746be226117781e63d0e013ef1a8 100644 (file)
@@ -6,6 +6,7 @@ import (
        "strings"
 
        "github.com/hashicorp/terraform/config"
+       "github.com/hashicorp/terraform/version"
 )
 
 // EvalCompareDiff is an EvalNode implementation that compares two diffs
@@ -60,7 +61,7 @@ func (n *EvalCompareDiff) Eval(ctx EvalContext) (interface{}, error) {
                                "\n"+
                                "Also include as much context as you can about your config, state, "+
                                "and the steps you performed to trigger this error.\n",
-                       n.Info.Id, Version, n.Info.Id, reason, one, two)
+                       n.Info.Id, version.Version, n.Info.Id, reason, one, two)
        }
 
        return nil, nil
@@ -255,11 +256,15 @@ func (n *EvalDiff) processIgnoreChanges(diff *InstanceDiff) error {
                containers := groupContainers(diff)
                keep := map[string]bool{}
                for _, v := range containers {
-                       if v.keepDiff() {
+                       if v.keepDiff(ignorableAttrKeys) {
                                // At least one key has changes, so list all the sibling keys
-                               // to keep in the diff.
+                               // to keep in the diff
                                for k := range v {
                                        keep[k] = true
+                                       // this key may have been added by the user to ignore, but
+                                       // if it's a subkey in a container, we need to un-ignore it
+                                       // to keep the complete containter.
+                                       delete(ignorableAttrKeys, k)
                                }
                        }
                }
@@ -291,10 +296,17 @@ func (n *EvalDiff) processIgnoreChanges(diff *InstanceDiff) error {
 // a group of key-*ResourceAttrDiff pairs from the same flatmapped container
 type flatAttrDiff map[string]*ResourceAttrDiff
 
-// we need to keep all keys if any of them have a diff
-func (f flatAttrDiff) keepDiff() bool {
-       for _, v := range f {
-               if !v.Empty() && !v.NewComputed {
+// we need to keep all keys if any of them have a diff that's not ignored
+func (f flatAttrDiff) keepDiff(ignoreChanges map[string]bool) bool {
+       for k, v := range f {
+               ignore := false
+               for attr := range ignoreChanges {
+                       if strings.HasPrefix(k, attr) {
+                               ignore = true
+                       }
+               }
+
+               if !v.Empty() && !v.NewComputed && !ignore {
                        return true
                }
        }