forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distributed_port_group_structure.go
198 lines (188 loc) · 8.06 KB
/
distributed_port_group_structure.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package vsphere
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/vmware/govmomi/vim25/types"
)
var distributedVirtualPortgroupPortgroupTypeAllowedValues = []string{
string(types.DistributedVirtualPortgroupPortgroupTypeEarlyBinding),
string(types.DistributedVirtualPortgroupPortgroupTypeEphemeral),
}
// schemaDVPortgroupConfigSpec returns schema items for resources that
// need to work with a DVPortgroupConfigSpec.
func schemaDVPortgroupConfigSpec() map[string]*schema.Schema {
s := map[string]*schema.Schema{
// VMwareDVSPortgroupPolicy
"block_override_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow the blocked setting of an individual port to override the setting in the portgroup.",
},
"live_port_moving_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow a live port to be moved in and out of the portgroup.",
},
"network_resource_pool_override_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow the network resource pool of an individual port to override the setting in the portgroup.",
},
"port_config_reset_at_disconnect": {
Type: schema.TypeBool,
Optional: true,
Description: "Reset the setting of any ports in this portgroup back to the default setting when the port disconnects.",
},
"shaping_override_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow the traffic shaping policies of an individual port to override the settings in the portgroup.",
},
"traffic_filter_override_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow any filter policies set on the individual port to override those in the portgroup.",
},
"netflow_override_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow the enabling or disabling of Netflow on a port, contrary to the policy in the portgroup.",
},
"security_policy_override_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow security policy settings on a port to override those on the portgroup.",
},
"uplink_teaming_override_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow the uplink teaming policies on a port to override those on the portgroup.",
},
"vlan_override_allowed": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow the VLAN configuration on a port to override those on the portgroup.",
},
// DVPortgroupConfigSpec
"auto_expand": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Auto-expands the port group beyond the port count configured in number_of_ports when necessary.",
},
"config_version": {
Type: schema.TypeString,
Computed: true,
Description: "Version string of the configuration that this spec is trying to change.",
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "The description of the portgroup.",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the portgroup.",
},
"number_of_ports": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The number of ports in this portgroup. The DVS will expand and shrink by modifying this setting.",
ValidateFunc: validation.IntAtLeast(0),
},
"port_name_format": {
Type: schema.TypeString,
Optional: true,
Description: "A template string to use when creating ports in the portgroup.",
},
"type": {
Type: schema.TypeString,
Optional: true,
Default: string(types.DistributedVirtualPortgroupPortgroupTypeEarlyBinding),
Description: "The type of portgroup. Can be one of earlyBinding (static) or ephemeral.",
ValidateFunc: validation.StringInSlice(distributedVirtualPortgroupPortgroupTypeAllowedValues, false),
},
"network_resource_pool_key": {
Type: schema.TypeString,
Optional: true,
Default: "-1",
Description: "The key of a network resource pool to associate with this portgroup.",
},
}
mergeSchema(s, schemaVMwareDVSPortSetting())
return s
}
// expandVMwareDVSPortgroupPolicy reads certain ResourceData keys and
// returns a VMwareDVSPortgroupPolicy.
func expandVMwareDVSPortgroupPolicy(d *schema.ResourceData) *types.VMwareDVSPortgroupPolicy {
obj := &types.VMwareDVSPortgroupPolicy{
DVPortgroupPolicy: types.DVPortgroupPolicy{
BlockOverrideAllowed: d.Get("block_override_allowed").(bool),
ShapingOverrideAllowed: d.Get("shaping_override_allowed").(bool),
LivePortMovingAllowed: d.Get("live_port_moving_allowed").(bool),
PortConfigResetAtDisconnect: d.Get("port_config_reset_at_disconnect").(bool),
NetworkResourcePoolOverrideAllowed: getBoolPtr(d, "network_resource_pool_override_allowed"),
TrafficFilterOverrideAllowed: getBoolPtr(d, "traffic_filter_override_allowed"),
},
VlanOverrideAllowed: d.Get("vlan_override_allowed").(bool),
UplinkTeamingOverrideAllowed: d.Get("uplink_teaming_override_allowed").(bool),
SecurityPolicyOverrideAllowed: d.Get("security_policy_override_allowed").(bool),
IpfixOverrideAllowed: getBoolPtr(d, "netflow_override_allowed"),
}
return obj
}
// flattenVMwareDVSPortgroupPolicy reads various fields from a
// VMwareDVSPortgroupPolicy into the passed in ResourceData.
func flattenVMwareDVSPortgroupPolicy(d *schema.ResourceData, obj *types.VMwareDVSPortgroupPolicy) error {
d.Set("block_override_allowed", obj.BlockOverrideAllowed)
d.Set("shaping_override_allowed", obj.ShapingOverrideAllowed)
d.Set("live_port_moving_allowed", obj.LivePortMovingAllowed)
d.Set("port_config_reset_at_disconnect", obj.PortConfigResetAtDisconnect)
d.Set("vlan_override_allowed", obj.VlanOverrideAllowed)
d.Set("uplink_teaming_override_allowed", obj.UplinkTeamingOverrideAllowed)
d.Set("security_policy_override_allowed", obj.SecurityPolicyOverrideAllowed)
setBoolPtr(d, "network_resource_pool_override_allowed", obj.NetworkResourcePoolOverrideAllowed)
setBoolPtr(d, "traffic_filter_override_allowed", obj.TrafficFilterOverrideAllowed)
setBoolPtr(d, "netflow_override_allowed", obj.IpfixOverrideAllowed)
return nil
}
// expandDVPortgroupConfigSpec reads certain ResourceData keys and
// returns a DVPortgroupConfigSpec.
func expandDVPortgroupConfigSpec(d *schema.ResourceData) types.DVPortgroupConfigSpec {
obj := types.DVPortgroupConfigSpec{
ConfigVersion: d.Get("config_version").(string),
Name: d.Get("name").(string),
NumPorts: int32(d.Get("number_of_ports").(int)),
PortNameFormat: d.Get("port_name_format").(string),
DefaultPortConfig: expandVMwareDVSPortSetting(d),
Description: d.Get("description").(string),
Type: d.Get("type").(string),
Policy: expandVMwareDVSPortgroupPolicy(d),
AutoExpand: getBoolPtr(d, "auto_expand"),
VmVnicNetworkResourcePoolKey: d.Get("network_resource_pool_key").(string),
}
return obj
}
// flattenDVPortgroupConfigInfo reads various fields from a
// DVPortgroupConfigInfo into the passed in ResourceData.
//
// This is the flatten counterpart to expandDVPortgroupConfigSpec.
func flattenDVPortgroupConfigInfo(d *schema.ResourceData, obj types.DVPortgroupConfigInfo) error {
d.Set("config_version", obj.ConfigVersion)
d.Set("name", obj.Name)
d.Set("number_of_ports", obj.NumPorts)
d.Set("port_name_format", obj.PortNameFormat)
d.Set("description", obj.Description)
d.Set("type", obj.Type)
setBoolPtr(d, "auto_expand", obj.AutoExpand)
d.Set("network_resource_pool_key", obj.VmVnicNetworkResourcePoolKey)
if err := flattenVMwareDVSPortSetting(d, obj.DefaultPortConfig.(*types.VMwareDVSPortSetting)); err != nil {
return err
}
if err := flattenVMwareDVSPortgroupPolicy(d, obj.Policy.(*types.VMwareDVSPortgroupPolicy)); err != nil {
return err
}
return nil
}