mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-05 05:24:01 +00:00
Initial support for multiple VLANs
This commit is contained in:
parent
40084fa433
commit
9261dcbf07
@ -361,7 +361,7 @@ This resource doesn't expose any additional attributes.
|
||||
* `enabled` - (Optional) Whether to enable the network device (defaults to `true`)
|
||||
* `mac_address` - (Optional) The MAC address
|
||||
* `model` - (Optional) The network device model (defaults to `virtio`)
|
||||
* `vlan_id` - (Optional) The VLAN identifier
|
||||
* `vlan_ids` - (Optional) The VLAN identifiers
|
||||
* `node_name` - (Required) The name of the node to assign the virtual machine to
|
||||
* `os_type` - (Optional) The OS type (defaults to `other`)
|
||||
* `pool_id` - (Optional) The ID of a pool to assign the virtual machine to
|
||||
|
@ -43,7 +43,6 @@ const (
|
||||
dvResourceVirtualEnvironmentVMNetworkDeviceEnabled = true
|
||||
dvResourceVirtualEnvironmentVMNetworkDeviceMACAddress = ""
|
||||
dvResourceVirtualEnvironmentVMNetworkDeviceModel = "virtio"
|
||||
dvResourceVirtualEnvironmentVMNetworkDeviceVLANID = -1
|
||||
dvResourceVirtualEnvironmentVMOSType = "other"
|
||||
dvResourceVirtualEnvironmentVMPoolID = ""
|
||||
dvResourceVirtualEnvironmentVMVMID = -1
|
||||
@ -95,7 +94,7 @@ const (
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled = "enabled"
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress = "mac_address"
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceModel = "model"
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANID = "vlan_id"
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs = "vlan_ids"
|
||||
mkResourceVirtualEnvironmentVMNodeName = "node_name"
|
||||
mkResourceVirtualEnvironmentVMOSType = "os_type"
|
||||
mkResourceVirtualEnvironmentVMPoolID = "pool_id"
|
||||
@ -552,12 +551,14 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
|
||||
Default: dvResourceVirtualEnvironmentVMNetworkDeviceModel,
|
||||
ValidateFunc: getNetworkDeviceModelValidator(),
|
||||
},
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANID: {
|
||||
Type: schema.TypeInt,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs: {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Description: "The VLAN identifier",
|
||||
Default: dvResourceVirtualEnvironmentVMNetworkDeviceVLANID,
|
||||
ValidateFunc: getVLANIDValidator(),
|
||||
Description: "The VLAN identifiers",
|
||||
DefaultFunc: func() (interface{}, error) {
|
||||
return make([]interface{}, 0), nil
|
||||
},
|
||||
Elem: &schema.Schema{Type: schema.TypeInt},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -838,7 +839,7 @@ func resourceVirtualEnvironmentVMCreate(d *schema.ResourceData, m interface{}) e
|
||||
enabled, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceEnabled].(bool)
|
||||
macAddress, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress].(string)
|
||||
model, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceModel].(string)
|
||||
vlanID, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceVLANID].(int)
|
||||
vlanIDs, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs].([]interface{})
|
||||
|
||||
device := proxmox.CustomNetworkDevice{
|
||||
Enabled: enabled,
|
||||
@ -853,8 +854,12 @@ func resourceVirtualEnvironmentVMCreate(d *schema.ResourceData, m interface{}) e
|
||||
device.MACAddress = &macAddress
|
||||
}
|
||||
|
||||
if vlanID != -1 {
|
||||
device.Trunks = []int{vlanID}
|
||||
if len(vlanIDs) > 0 {
|
||||
device.Trunks = make([]int, len(vlanIDs))
|
||||
|
||||
for vi, vv := range vlanIDs {
|
||||
device.Trunks[vi] = vv.(int)
|
||||
}
|
||||
}
|
||||
|
||||
networkDeviceObjects[i] = device
|
||||
|
@ -287,7 +287,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceModel,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANID,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs,
|
||||
})
|
||||
|
||||
testSchemaValueTypes(t, networkDeviceSchema, []string{
|
||||
@ -295,12 +295,12 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceModel,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANID,
|
||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs,
|
||||
}, []schema.ValueType{
|
||||
schema.TypeString,
|
||||
schema.TypeBool,
|
||||
schema.TypeString,
|
||||
schema.TypeString,
|
||||
schema.TypeInt,
|
||||
schema.TypeList,
|
||||
})
|
||||
}
|
||||
|
@ -118,24 +118,33 @@ func getQEMUAgentTypeValidator() schema.SchemaValidateFunc {
|
||||
return validation.StringInSlice([]string{"isa", "virtio"}, false)
|
||||
}
|
||||
|
||||
func getVLANIDValidator() schema.SchemaValidateFunc {
|
||||
func getVLANIDsValidator() schema.SchemaValidateFunc {
|
||||
return func(i interface{}, k string) (ws []string, es []error) {
|
||||
min := 1
|
||||
max := 4094
|
||||
|
||||
v, ok := i.(int)
|
||||
list, ok := i.([]interface{})
|
||||
|
||||
if !ok {
|
||||
es = append(es, fmt.Errorf("expected type of %s to be int", k))
|
||||
es = append(es, fmt.Errorf("expected type of %s to be []interface{}", k))
|
||||
return
|
||||
}
|
||||
|
||||
for li, lv := range list {
|
||||
v, ok := lv.(int)
|
||||
|
||||
if !ok {
|
||||
es = append(es, fmt.Errorf("expected type of %s[%d] to be int", k, li))
|
||||
return
|
||||
}
|
||||
|
||||
if v != -1 {
|
||||
if v < min || v > max {
|
||||
es = append(es, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v))
|
||||
es = append(es, fmt.Errorf("expected %s[%d] to be in the range (%d - %d), got %d", k, li, min, max, v))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user