-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_terraform.go
98 lines (85 loc) · 1.94 KB
/
utils_terraform.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
package uaa
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// getChangedValueString
func getChangedValueString(key string, updated *bool, d *schema.ResourceData) *string {
if d.HasChange(key) {
vv := d.Get(key).(string)
*updated = true
return &vv
} else if v, ok := d.GetOk(key); ok {
vv := v.(string)
return &vv
}
return nil
}
// getChangedValueInt
func getChangedValueInt(key string, updated *bool, d *schema.ResourceData) *int {
if d.HasChange(key) {
vv := d.Get(key).(int)
*updated = true
return &vv
} else if v, ok := d.GetOk(key); ok {
vv := v.(int)
return &vv
}
return nil
}
// getChangedValueBool
func getChangedValueBool(key string, updated *bool, d *schema.ResourceData) *bool {
if d.HasChange(key) {
vv := d.Get(key).(bool)
*updated = true
return &vv
} else if v, ok := d.GetOk(key); ok {
vv := v.(bool)
return &vv
}
return nil
}
// getChangedValueStringList
func getChangedValueStringList(key string, updated *bool, d *schema.ResourceData) *[]string {
var a []interface{}
if d.HasChange(key) {
a = d.Get(key).(*schema.Set).List()
*updated = true
} else if v, ok := d.GetOk(key); ok {
a = v.(*schema.Set).List()
}
if a != nil {
aa := []string{}
for _, vv := range a {
aa = append(aa, vv.(string))
}
return &aa
}
return nil
}
// getResourceChange -
func getResourceChange(key string, d *schema.ResourceData) (bool, string, string) {
old, cur := d.GetChange(key)
return old != cur, old.(string), cur.(string)
}
// getListChanges -
func getListChanges(old interface{}, new interface{}) (remove []string, add []string) {
var a bool
for _, o := range old.(*schema.Set).List() {
remove = append(remove, o.(string))
}
for _, n := range new.(*schema.Set).List() {
nn := n.(string)
a = true
for i, r := range remove {
if nn == r {
remove = append(remove[:i], remove[i+1:]...)
a = false
break
}
}
if a {
add = append(add, nn)
}
}
return
}