forked from hashicorp/terraform-provider-vault
/
util.go
53 lines (45 loc) · 1.09 KB
/
util.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
package vault
import (
"encoding/json"
"log"
"reflect"
"strings"
"github.com/hashicorp/terraform/helper/schema"
)
func jsonDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
var oldJSON, newJSON interface{}
err := json.Unmarshal([]byte(old), &oldJSON)
if err != nil {
log.Printf("[ERROR] Version of %q in state is not valid JSON: %s", k, err)
return false
}
err = json.Unmarshal([]byte(new), &newJSON)
if err != nil {
log.Printf("[ERROR] Version of %q in config is not valid JSON: %s", k, err)
return true
}
return reflect.DeepEqual(oldJSON, newJSON)
}
func toStringArray(input []interface{}) []string {
output := make([]string, len(input))
for i, item := range input {
output[i] = item.(string)
}
return output
}
func is404(err error) bool {
return strings.Contains(err.Error(), "Code: 404")
}
func calculateConflictsWith(self string, group []string) []string {
if len(group) < 2 {
return []string{}
}
results := make([]string, 0, len(group)-2)
for _, item := range group {
if item == self {
continue
}
results = append(results, item)
}
return results
}