-
Notifications
You must be signed in to change notification settings - Fork 55
/
fields_spotinst_mrscaler_aws_instance_groups.go
74 lines (61 loc) · 2.24 KB
/
fields_spotinst_mrscaler_aws_instance_groups.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
package mrscaler_aws_instance_groups
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/spotinst/spotinst-sdk-go/service/mrscaler"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/terraform-provider-spotinst/spotinst/commons"
)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Setup
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
SetupCoreGroup(fieldsMap)
SetupMasterGroup(fieldsMap)
SetupTaskGroup(fieldsMap)
}
func expandScalerAWSBlockDevices(data interface{}) ([]*mrscaler.BlockDeviceConfig, error) {
list := data.(*schema.Set).List()
devices := make([]*mrscaler.BlockDeviceConfig, 0, len(list))
for _, item := range list {
m := item.(map[string]interface{})
blockDevice := &mrscaler.BlockDeviceConfig{VolumeSpecification: &mrscaler.VolumeSpecification{}}
if v, ok := m[string(VolumesPerInstance)].(int); ok {
blockDevice.SetVolumesPerInstance(spotinst.Int(v))
}
if v, ok := m[string(VolumeType)].(string); ok {
blockDevice.VolumeSpecification.SetVolumeType(spotinst.String(v))
}
if v, ok := m[string(SizeInGB)].(int); ok {
blockDevice.VolumeSpecification.SetSizeInGB(spotinst.Int(v))
}
if v, ok := m[string(IOPS)].(int); ok && v > 0 {
blockDevice.VolumeSpecification.SetIOPS(spotinst.Int(v))
}
devices = append(devices, blockDevice)
}
return devices, nil
}
func expandInstanceTypesList(instanceTypes interface{}) []string {
list := instanceTypes.([]interface{})
types := make([]string, 0, len(list))
for _, str := range list {
if typ, ok := str.(string); ok {
types = append(types, typ)
}
}
return types
}
func flattenMRscalerEBSBlockDevices(devices []*mrscaler.BlockDeviceConfig) []interface{} {
result := make([]interface{}, 0, len(devices))
for _, dev := range devices {
m := make(map[string]interface{})
m[string(VolumesPerInstance)] = spotinst.IntValue(dev.VolumesPerInstance)
if dev.VolumeSpecification != nil {
m[string(SizeInGB)] = spotinst.IntValue(dev.VolumeSpecification.SizeInGB)
m[string(VolumeType)] = spotinst.StringValue(dev.VolumeSpecification.VolumeType)
m[string(IOPS)] = spotinst.IntValue(dev.VolumeSpecification.IOPS)
}
result = append(result, m)
}
return result
}