-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
features.go
89 lines (80 loc) · 2.21 KB
/
features.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
package provider
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
)
func schemaFeatures() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
// TODO: make this Required in 2.0
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"virtual_machine": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"delete_os_disk_on_deletion": {
Type: schema.TypeBool,
Required: true,
},
},
},
},
"virtual_machine_scale_set": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"roll_instances_when_required": {
Type: schema.TypeBool,
Required: true,
},
},
},
},
},
},
}
}
func expandFeatures(input []interface{}) features.UserFeatures {
// TODO: in 2.0 when Required this can become:
//val := input[0].(map[string]interface{})
var val map[string]interface{}
if len(input) > 0 {
val = input[0].(map[string]interface{})
}
// these are the defaults if omitted from the config
features := features.UserFeatures{
// NOTE: ensure all nested objects are fully populated
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: true,
},
VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{
RollInstancesWhenRequired: true,
},
}
if raw, ok := val["virtual_machine"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
virtualMachinesRaw := items[0].(map[string]interface{})
if v, ok := virtualMachinesRaw["delete_os_disk_on_deletion"]; ok {
features.VirtualMachine.DeleteOSDiskOnDeletion = v.(bool)
}
}
}
if raw, ok := val["virtual_machine_scale_set"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
scaleSetRaw := items[0].(map[string]interface{})
if v, ok := scaleSetRaw["roll_instances_when_required"]; ok {
features.VirtualMachineScaleSet.RollInstancesWhenRequired = v.(bool)
}
}
}
return features
}