This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
forked from huaweicloud/terraform-provider-huaweicloud
/
custom_functions.go
132 lines (110 loc) · 3.79 KB
/
custom_functions.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package huaweicloud
import (
"fmt"
"reflect"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func expandCdmClusterV1CreateAutoRemind(d interface{}, arrayIndex map[string]int) (interface{}, error) {
email, _ := navigateValue(d, []string{"email"}, nil)
e, eok := email.([]interface{})
phone, _ := navigateValue(d, []string{"phone_num"}, nil)
p, pok := phone.([]interface{})
return (eok && len(e) > 0) || (pok && len(p) > 0), nil
}
func expandCdmClusterV1CreateClusterIsScheduleBootOff(d interface{}, arrayIndex map[string]int) (interface{}, error) {
on, _ := navigateValue(d, []string{"schedule_boot_time"}, nil)
on1, ok1 := on.(string)
off, _ := navigateValue(d, []string{"schedule_off_time"}, nil)
off1, ok2 := off.(string)
return (ok1 && on1 != "") || (ok2 && off1 != ""), nil
}
func checkCssClusterV1ExtendClusterFinished(data interface{}) bool {
//actions --- the behaviors on a cluster
v, err := navigateValue(data, []string{"actions"}, nil)
e, err := isEmptyValue(reflect.ValueOf(v))
if err == nil && !e {
return false
}
//actionProgress --- indicates the progress in percentage
v, err = navigateValue(data, []string{"actionProgress"}, nil)
e, err = isEmptyValue(reflect.ValueOf(v))
if err == nil && !e {
return false
}
instances, err := navigateValue(data, []string{"instances"}, nil)
if err != nil {
return false
}
if v, ok := instances.([]interface{}); ok {
if len(v) == 0 {
return false
}
for _, item := range v {
status, err := navigateValue(item, []string{"status"}, nil)
if err != nil {
return false
}
if s, ok := status.(string); !ok || "200" != s {
return false
}
}
return true
}
return false
}
func expandCssClusterV1ExtendClusterNodeNum(d interface{}, arrayIndex map[string]int) (interface{}, error) {
t, _ := navigateValue(d, []string{"terraform_resource_data"}, nil)
rd := t.(*schema.ResourceData)
oldv, newv := rd.GetChange("expect_node_num")
v := newv.(int) - oldv.(int)
if v < 0 {
return 0, fmt.Errorf("expect_node_num only supports to be extended")
}
return v, nil
}
func expandCssClusterV1ExtendClusterVolumeSize(d interface{}, arrayIndex map[string]int) (interface{}, error) {
t, _ := navigateValue(d, []string{"terraform_resource_data"}, nil)
rd := t.(*schema.ResourceData)
//volume size location: reference to the Schema of css_cluster_v1
oldv, newv := rd.GetChange("node_config.0.volume.0.size")
v := newv.(int) - oldv.(int)
if v < 0 {
return 0, fmt.Errorf("volume size only supports to be extended")
}
return v, nil
}
func expandRdsInstanceV3CreateRegion(d interface{}, arrayIndex map[string]int) (interface{}, error) {
return navigateValue(d, []string{"region"}, arrayIndex)
}
func flattenRdsInstanceV3HAReplicationMode(d interface{}, arrayIndex map[string]int, currentValue interface{}) (interface{}, error) {
v, err := navigateValue(d, []string{"list", "flavor_ref"}, nil)
if err != nil {
return nil, err
}
if strings.HasSuffix(v.(string), ".ha") {
return navigateValue(d, []string{"list", "ha", "replication_mode"}, nil)
}
return "", nil
}
func expandDisStreamV2CreateAutoCaleEnable(d interface{}, arrayIndex map[string]int) (interface{}, error) {
max, _ := navigateValue(d, []string{"auto_scale_max_partition_count"}, nil)
max1, ok1 := max.(int)
min, _ := navigateValue(d, []string{"auto_scale_min_partition_count"}, nil)
min1, ok2 := min.(int)
return (ok1 && max1 > 0) && (ok2 && min1 > 0), nil
}
func checkCsClusterV1DeleteFinished(data interface{}) bool {
c, err := navigateValue(data, []string{"error_id"}, nil)
if err != nil {
return false
}
return "CS.20005" == convertToStr(c)
}
func checkCsPeeringConnectV1DeleteFinished(data interface{}) bool {
c, err := navigateValue(data, []string{"error_id"}, nil)
if err != nil {
return false
}
return "CS.22103" == convertToStr(c)
}