-
Notifications
You must be signed in to change notification settings - Fork 10
/
common_volcengine_scaling_policy.go
47 lines (40 loc) · 1.37 KB
/
common_volcengine_scaling_policy.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
package scaling_policy
import (
"fmt"
"strings"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
var scalingPolicyImporter = func(data *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) {
items := strings.Split(data.Id(), ":")
if len(items) != 2 {
return []*schema.ResourceData{data}, fmt.Errorf("import id must split with ':'")
}
if err := data.Set("scaling_policy_id", items[1]); err != nil {
return []*schema.ResourceData{data}, err
}
if err := data.Set("scaling_group_id", items[0]); err != nil {
return []*schema.ResourceData{data}, err
}
return []*schema.ResourceData{data}, nil
}
var policyDiffSuppressFunc = func(policyTypes ...string) func(k, old, new string, d *schema.ResourceData) bool {
tyMap := make(map[string]bool)
for _, policyType := range policyTypes {
tyMap[policyType] = true
}
return func(k, old, new string, d *schema.ResourceData) bool {
return !tyMap[d.Get("scaling_policy_type").(string)]
}
}
func timeValidation(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return warnings, errors
}
if _, err := time.Parse("2006-01-02T15:04Z", v); err != nil {
errors = append(errors, fmt.Errorf("expected %q to be a valid RFC3339 date, got %q: %+v", k, i, err))
}
return warnings, errors
}