From a5c1bf1b3626aeecc5058ac09ff3173f065ff588 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 16 Jun 2016 18:23:26 -0400 Subject: [PATCH] Don't check any parts of a computed hash in Same When checking for "same" values in a computed hash, not only might some of the values differ between versions changing the hash, but there may be fields not included at all in the original map, and different overall counts. Instead of trying to match individual set fields with different hashes, remove any hashed key longer than the computed key with the same base name. --- terraform/diff.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/terraform/diff.go b/terraform/diff.go index 8c26e16ff5..088c09c5a0 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -443,35 +443,30 @@ func (d *InstanceDiff) Same(d2 *InstanceDiff) (bool, string) { // values. So check if there is an approximate hash in the key // and if so, try to match the key. if strings.Contains(k, "~") { - // TODO (SvH): There should be a better way to do this... parts := strings.Split(k, ".") - parts2 := strings.Split(k, ".") + parts2 := append([]string(nil), parts...) + re := regexp.MustCompile(`^~\d+$`) for i, part := range parts { if re.MatchString(part) { + // we're going to consider this the base of a + // computed hash, and remove all longer matching fields + ok = true + parts2[i] = `\d+` + parts2 = parts2[:i+1] + break } } - re, err := regexp.Compile("^" + strings.Join(parts2, `\.`) + "$") + + re, err := regexp.Compile("^" + strings.Join(parts2, `\.`)) if err != nil { return false, fmt.Sprintf("regexp failed to compile; err: %#v", err) } + for k2, _ := range checkNew { if re.MatchString(k2) { delete(checkNew, k2) - - if diffOld.NewComputed && strings.HasSuffix(k, ".#") { - // This is a computed list or set, so remove any keys with this - // prefix from the check list. - prefix := k2[:len(k2)-1] - for k2, _ := range checkNew { - if strings.HasPrefix(k2, prefix) { - delete(checkNew, k2) - } - } - } - ok = true - break } } }