-
Notifications
You must be signed in to change notification settings - Fork 75
/
diff_suppress_funcs.go
106 lines (90 loc) · 3.01 KB
/
diff_suppress_funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package common
import (
"reflect"
"regexp"
"sort"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
awspolicy "github.com/jen20/awspolicyequivalence"
)
func SuppressEquivalentAwsPolicyDiffs(_, old, new string, _ *schema.ResourceData) bool {
equivalent, err := awspolicy.PoliciesAreEquivalent(old, new)
if err != nil {
return false
}
return equivalent
}
// SuppressDiffAll suppress all changes?
func SuppressDiffAll(_, _, _ string, _ *schema.ResourceData) bool {
return true
}
// SuppressMinDisk suppress changes if we get a computed min_disk_gb if value is unspecified (default 0)
func SuppressMinDisk(_, old, new string, _ *schema.ResourceData) bool {
return new == "0" || old == new
}
// SuppressExternalGateway suppress changes if we don't specify an external gateway, but one is specified for us
func SuppressExternalGateway(_, old, new string, _ *schema.ResourceData) bool {
return new == "" || old == new
}
// SuppressComputedFixedWhenFloatingIp suppress changes if we get a fixed ip when not expecting one,
// if we have a floating ip (generates fixed ip).
func SuppressComputedFixedWhenFloatingIp(_, old, new string, d *schema.ResourceData) bool {
if v, ok := d.GetOk("floating_ip"); ok && v != "" {
return new == "" || old == new
}
return false
}
func SuppressRdsNameDiffs(_, old, new string, _ *schema.ResourceData) bool {
if strings.HasPrefix(old, new) && strings.HasSuffix(old, "_node0") {
return true
}
return false
}
func SuppressLBWhitelistDiffs(_, old, new string, _ *schema.ResourceData) bool {
if len(old) != len(new) {
return false
}
oldArray := strings.Split(old, ",")
newArray := strings.Split(new, ",")
sort.Strings(oldArray)
sort.Strings(newArray)
return reflect.DeepEqual(oldArray, newArray)
}
func SuppressSmartVersionDiff(_, old, new string, _ *schema.ResourceData) bool {
compiledVer := regexp.MustCompile(`v(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-(\w+))?$`)
oldArray := compiledVer.FindStringSubmatch(old)
newArray := compiledVer.FindStringSubmatch(new)
if oldArray == nil {
return false
}
for i := 1; i < len(newArray); i++ {
if oldArray[i] == "" || newArray[i] == "" {
return true
}
if oldArray[i] != newArray[i] {
return false
}
}
return false
}
func SuppressCaseInsensitive(_, old, new string, _ *schema.ResourceData) bool {
return strings.EqualFold(old, new)
}
func SuppressEqualZoneNames(_, old, new string, _ *schema.ResourceData) bool {
oldShort := strings.TrimSuffix(old, ".")
newShort := strings.TrimSuffix(new, ".")
return oldShort == newShort
}
func SuppressStrippedNewLines(_, old, new string, _ *schema.ResourceData) bool {
newline := "\n"
return strings.Trim(old, newline) == strings.Trim(new, newline)
}
func SuppressEmptyStringSHA(k, old, new string, d *schema.ResourceData) bool {
// Sometimes the API responds with the equivalent, empty SHA1 sum
// echo -n "" | shasum
if (old == "da39a3ee5e6b4b0d3255bfef95601890afd80709" && new == "") ||
(old == "" && new == "da39a3ee5e6b4b0d3255bfef95601890afd80709") {
return true
}
return false
}