-
Notifications
You must be signed in to change notification settings - Fork 55
/
fields_spotinst_ocean_gke_strategy.go
61 lines (50 loc) · 1.79 KB
/
fields_spotinst_ocean_gke_strategy.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
package ocean_gke_strategy
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/terraform-provider-spotinst/spotinst/commons"
)
func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
fieldsMap[DrainingTimeout] = commons.NewGenericField(
commons.OceanGKEStrategy,
DrainingTimeout,
&schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.GKEClusterWrapper)
cluster := clusterWrapper.GetCluster()
var value *int = nil
if cluster.Strategy != nil && cluster.Strategy.DrainingTimeout != nil {
value = cluster.Strategy.DrainingTimeout
}
if value != nil {
if err := resourceData.Set(string(DrainingTimeout), spotinst.IntValue(value)); err != nil {
return fmt.Errorf(string(commons.FailureFieldReadPattern), string(DrainingTimeout), err)
}
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.GKEClusterWrapper)
cluster := clusterWrapper.GetCluster()
if v, ok := resourceData.GetOkExists(string(DrainingTimeout)); ok {
cluster.Strategy.SetDrainingTimeout(spotinst.Int(v.(int)))
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.GKEClusterWrapper)
cluster := clusterWrapper.GetCluster()
var dt *int = nil
if v, ok := resourceData.Get(string(DrainingTimeout)).(int); ok && v > 0 {
dt = spotinst.Int(v)
}
cluster.Strategy.SetDrainingTimeout(dt)
return nil
},
nil,
)
}