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`)
|
* `enabled` - (Optional) Whether to enable the network device (defaults to `true`)
|
||||||
* `mac_address` - (Optional) The MAC address
|
* `mac_address` - (Optional) The MAC address
|
||||||
* `model` - (Optional) The network device model (defaults to `virtio`)
|
* `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
|
* `node_name` - (Required) The name of the node to assign the virtual machine to
|
||||||
* `os_type` - (Optional) The OS type (defaults to `other`)
|
* `os_type` - (Optional) The OS type (defaults to `other`)
|
||||||
* `pool_id` - (Optional) The ID of a pool to assign the virtual machine to
|
* `pool_id` - (Optional) The ID of a pool to assign the virtual machine to
|
||||||
|
@ -43,7 +43,6 @@ const (
|
|||||||
dvResourceVirtualEnvironmentVMNetworkDeviceEnabled = true
|
dvResourceVirtualEnvironmentVMNetworkDeviceEnabled = true
|
||||||
dvResourceVirtualEnvironmentVMNetworkDeviceMACAddress = ""
|
dvResourceVirtualEnvironmentVMNetworkDeviceMACAddress = ""
|
||||||
dvResourceVirtualEnvironmentVMNetworkDeviceModel = "virtio"
|
dvResourceVirtualEnvironmentVMNetworkDeviceModel = "virtio"
|
||||||
dvResourceVirtualEnvironmentVMNetworkDeviceVLANID = -1
|
|
||||||
dvResourceVirtualEnvironmentVMOSType = "other"
|
dvResourceVirtualEnvironmentVMOSType = "other"
|
||||||
dvResourceVirtualEnvironmentVMPoolID = ""
|
dvResourceVirtualEnvironmentVMPoolID = ""
|
||||||
dvResourceVirtualEnvironmentVMVMID = -1
|
dvResourceVirtualEnvironmentVMVMID = -1
|
||||||
@ -95,7 +94,7 @@ const (
|
|||||||
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled = "enabled"
|
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled = "enabled"
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress = "mac_address"
|
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress = "mac_address"
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceModel = "model"
|
mkResourceVirtualEnvironmentVMNetworkDeviceModel = "model"
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANID = "vlan_id"
|
mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs = "vlan_ids"
|
||||||
mkResourceVirtualEnvironmentVMNodeName = "node_name"
|
mkResourceVirtualEnvironmentVMNodeName = "node_name"
|
||||||
mkResourceVirtualEnvironmentVMOSType = "os_type"
|
mkResourceVirtualEnvironmentVMOSType = "os_type"
|
||||||
mkResourceVirtualEnvironmentVMPoolID = "pool_id"
|
mkResourceVirtualEnvironmentVMPoolID = "pool_id"
|
||||||
@ -552,12 +551,14 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
|
|||||||
Default: dvResourceVirtualEnvironmentVMNetworkDeviceModel,
|
Default: dvResourceVirtualEnvironmentVMNetworkDeviceModel,
|
||||||
ValidateFunc: getNetworkDeviceModelValidator(),
|
ValidateFunc: getNetworkDeviceModelValidator(),
|
||||||
},
|
},
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANID: {
|
mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs: {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeList,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "The VLAN identifier",
|
Description: "The VLAN identifiers",
|
||||||
Default: dvResourceVirtualEnvironmentVMNetworkDeviceVLANID,
|
DefaultFunc: func() (interface{}, error) {
|
||||||
ValidateFunc: getVLANIDValidator(),
|
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)
|
enabled, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceEnabled].(bool)
|
||||||
macAddress, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress].(string)
|
macAddress, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress].(string)
|
||||||
model, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceModel].(string)
|
model, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceModel].(string)
|
||||||
vlanID, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceVLANID].(int)
|
vlanIDs, _ := block[mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs].([]interface{})
|
||||||
|
|
||||||
device := proxmox.CustomNetworkDevice{
|
device := proxmox.CustomNetworkDevice{
|
||||||
Enabled: enabled,
|
Enabled: enabled,
|
||||||
@ -853,8 +854,12 @@ func resourceVirtualEnvironmentVMCreate(d *schema.ResourceData, m interface{}) e
|
|||||||
device.MACAddress = &macAddress
|
device.MACAddress = &macAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
if vlanID != -1 {
|
if len(vlanIDs) > 0 {
|
||||||
device.Trunks = []int{vlanID}
|
device.Trunks = make([]int, len(vlanIDs))
|
||||||
|
|
||||||
|
for vi, vv := range vlanIDs {
|
||||||
|
device.Trunks[vi] = vv.(int)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
networkDeviceObjects[i] = device
|
networkDeviceObjects[i] = device
|
||||||
|
@ -287,7 +287,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled,
|
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled,
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress,
|
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress,
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceModel,
|
mkResourceVirtualEnvironmentVMNetworkDeviceModel,
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANID,
|
mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs,
|
||||||
})
|
})
|
||||||
|
|
||||||
testSchemaValueTypes(t, networkDeviceSchema, []string{
|
testSchemaValueTypes(t, networkDeviceSchema, []string{
|
||||||
@ -295,12 +295,12 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled,
|
mkResourceVirtualEnvironmentVMNetworkDeviceEnabled,
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress,
|
mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress,
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceModel,
|
mkResourceVirtualEnvironmentVMNetworkDeviceModel,
|
||||||
mkResourceVirtualEnvironmentVMNetworkDeviceVLANID,
|
mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs,
|
||||||
}, []schema.ValueType{
|
}, []schema.ValueType{
|
||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
schema.TypeBool,
|
schema.TypeBool,
|
||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
schema.TypeInt,
|
schema.TypeList,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -118,23 +118,32 @@ func getQEMUAgentTypeValidator() schema.SchemaValidateFunc {
|
|||||||
return validation.StringInSlice([]string{"isa", "virtio"}, false)
|
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) {
|
return func(i interface{}, k string) (ws []string, es []error) {
|
||||||
min := 1
|
min := 1
|
||||||
max := 4094
|
max := 4094
|
||||||
|
|
||||||
v, ok := i.(int)
|
list, ok := i.([]interface{})
|
||||||
|
|
||||||
if !ok {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if v != -1 {
|
for li, lv := range list {
|
||||||
if v < min || v > max {
|
v, ok := lv.(int)
|
||||||
es = append(es, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v))
|
|
||||||
|
if !ok {
|
||||||
|
es = append(es, fmt.Errorf("expected type of %s[%d] to be int", k, li))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v != -1 {
|
||||||
|
if v < min || v > max {
|
||||||
|
es = append(es, fmt.Errorf("expected %s[%d] to be in the range (%d - %d), got %d", k, li, min, max, v))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user