mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 11:02:59 +00:00
feat(vm): add support for disconnected
attribute in network interface (#1129)
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
29b5438faf
commit
11ca880f28
@ -408,20 +408,17 @@ output "ubuntu_vm_public_key" {
|
||||
it (defaults to `false`).
|
||||
- `name` - (Optional) The virtual machine name.
|
||||
- `network_device` - (Optional) A network device (multiple blocks supported).
|
||||
- `bridge` - (Optional) The name of the network bridge (defaults
|
||||
to `vmbr0`).
|
||||
- `enabled` - (Optional) Whether to enable the network device (defaults
|
||||
to `true`).
|
||||
- `firewall` - (Optional) Whether this interface's firewall rules should be
|
||||
used (defaults to `false`).
|
||||
- `bridge` - (Optional) The name of the network bridge (defaults to `vmbr0`).
|
||||
- `disconnected` - (Optional) Whether to disconnect the network device from the network (defaults to `false`).
|
||||
- `enabled` - (Optional) Whether to enable the network device (defaults to `true`).
|
||||
- `firewall` - (Optional) Whether this interface's firewall rules should be used (defaults to `false`).
|
||||
- `mac_address` - (Optional) The MAC address.
|
||||
- `model` - (Optional) The network device model (defaults to `virtio`).
|
||||
- `e1000` - Intel E1000.
|
||||
- `rtl8139` - Realtek RTL8139.
|
||||
- `virtio` - VirtIO (paravirtualized).
|
||||
- `vmxnet3` - VMware vmxnet3.
|
||||
- `mtu` - (Optional) Force MTU, for VirtIO only. Set to 1 to use the bridge
|
||||
MTU. Cannot be larger than the bridge MTU.
|
||||
- `mtu` - (Optional) Force MTU, for VirtIO only. Set to 1 to use the bridge MTU. Cannot be larger than the bridge MTU.
|
||||
- `queues` - (Optional) The number of queues for VirtIO (1..64).
|
||||
- `rate_limit` - (Optional) The rate limit in megabytes per second.
|
||||
- `vlan_id` - (Optional) The VLAN identifier.
|
||||
|
@ -109,9 +109,9 @@ func TestAccResourceVMNetwork(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
step resource.TestStep
|
||||
step []resource.TestStep
|
||||
}{
|
||||
{"network interfaces", resource.TestStep{
|
||||
{"network interfaces", []resource.TestStep{{
|
||||
Config: providerConfig + `
|
||||
resource "proxmox_virtual_environment_file" "cloud_config" {
|
||||
content_type = "snippets"
|
||||
@ -179,7 +179,41 @@ EOF
|
||||
"network_device.0.trunks": "10;20;30",
|
||||
}),
|
||||
),
|
||||
}},
|
||||
}}},
|
||||
{"network device disconnected", []resource.TestStep{{
|
||||
Config: `
|
||||
resource "proxmox_virtual_environment_vm" "test_vm_network2" {
|
||||
node_name = "pve"
|
||||
started = false
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
}`,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testResourceAttributes("proxmox_virtual_environment_vm.test_vm_network2", map[string]string{
|
||||
"network_device.0.bridge": "vmbr0",
|
||||
"network_device.0.disconnected": "false",
|
||||
}),
|
||||
),
|
||||
}, {
|
||||
Config: `
|
||||
resource "proxmox_virtual_environment_vm" "test_vm_network2" {
|
||||
node_name = "pve"
|
||||
started = false
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
disconnected = true
|
||||
}
|
||||
}`,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testResourceAttributes("proxmox_virtual_environment_vm.test_vm_network2", map[string]string{
|
||||
"network_device.0.bridge": "vmbr0",
|
||||
"network_device.0.disconnected": "true",
|
||||
}),
|
||||
),
|
||||
}}},
|
||||
}
|
||||
|
||||
accProviders := testAccMuxProviders(context.Background(), t)
|
||||
@ -191,7 +225,7 @@ EOF
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
ProtoV6ProviderFactories: accProviders,
|
||||
Steps: []resource.TestStep{tt.step},
|
||||
Steps: tt.step,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -89,16 +89,16 @@ type CustomEFIDisk struct {
|
||||
|
||||
// CustomNetworkDevice handles QEMU network device parameters.
|
||||
type CustomNetworkDevice struct {
|
||||
Model string `json:"model" url:"model"`
|
||||
Bridge *string `json:"bridge,omitempty" url:"bridge,omitempty"`
|
||||
Enabled bool `json:"-" url:"-"`
|
||||
Bridge *string `json:"bridge,omitempty" url:"bridge,omitempty"`
|
||||
Firewall *types.CustomBool `json:"firewall,omitempty" url:"firewall,omitempty,int"`
|
||||
LinkDown *types.CustomBool `json:"link_down,omitempty" url:"link_down,omitempty,int"`
|
||||
MACAddress *string `json:"macaddr,omitempty" url:"macaddr,omitempty"`
|
||||
MTU *int `json:"mtu,omitempty" url:"mtu,omitempty"`
|
||||
Model string `json:"model" url:"model"`
|
||||
Queues *int `json:"queues,omitempty" url:"queues,omitempty"`
|
||||
RateLimit *float64 `json:"rate,omitempty" url:"rate,omitempty"`
|
||||
Tag *int `json:"tag,omitempty" url:"tag,omitempty"`
|
||||
MTU *int `json:"mtu,omitempty" url:"mtu,omitempty"`
|
||||
Trunks []int `json:"trunks,omitempty" url:"trunks,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -23,15 +23,16 @@ func GetNetworkDeviceObjects(d *schema.ResourceData) (vms.CustomNetworkDevices,
|
||||
block := networkDeviceEntry.(map[string]interface{})
|
||||
|
||||
bridge := block[mkNetworkDeviceBridge].(string)
|
||||
disconnected := types.CustomBool(block[mkNetworkDeviceDisconnected].(bool))
|
||||
enabled := block[mkNetworkDeviceEnabled].(bool)
|
||||
firewall := types.CustomBool(block[mkNetworkDeviceFirewall].(bool))
|
||||
macAddress := block[mkNetworkDeviceMACAddress].(string)
|
||||
model := block[mkNetworkDeviceModel].(string)
|
||||
mtu := block[mkNetworkDeviceMTU].(int)
|
||||
queues := block[mkNetworkDeviceQueues].(int)
|
||||
rateLimit := block[mkNetworkDeviceRateLimit].(float64)
|
||||
vlanID := block[mkNetworkDeviceVLANID].(int)
|
||||
trunks := block[mkNetworkDeviceTrunks].(string)
|
||||
mtu := block[mkNetworkDeviceMTU].(int)
|
||||
vlanID := block[mkNetworkDeviceVLANID].(int)
|
||||
|
||||
device := vms.CustomNetworkDevice{
|
||||
Enabled: enabled,
|
||||
@ -43,6 +44,10 @@ func GetNetworkDeviceObjects(d *schema.ResourceData) (vms.CustomNetworkDevices,
|
||||
device.Bridge = &bridge
|
||||
}
|
||||
|
||||
if disconnected {
|
||||
device.LinkDown = &disconnected
|
||||
}
|
||||
|
||||
if macAddress != "" {
|
||||
device.MACAddress = &macAddress
|
||||
}
|
||||
@ -145,6 +150,12 @@ func ReadNetworkDeviceObjects(d *schema.ResourceData, vmConfig *vms.GetResponseD
|
||||
|
||||
networkDevice[mkNetworkDeviceEnabled] = nd.Enabled
|
||||
|
||||
if nd.LinkDown != nil {
|
||||
networkDevice[mkNetworkDeviceDisconnected] = *nd.LinkDown
|
||||
} else {
|
||||
networkDevice[mkNetworkDeviceDisconnected] = false
|
||||
}
|
||||
|
||||
if nd.Firewall != nil {
|
||||
networkDevice[mkNetworkDeviceFirewall] = *nd.Firewall
|
||||
} else {
|
||||
|
@ -17,30 +17,31 @@ const (
|
||||
dvNetworkDeviceBridge = "vmbr0"
|
||||
dvNetworkDeviceEnabled = true
|
||||
dvNetworkDeviceFirewall = false
|
||||
dvNetworkDeviceMTU = 0
|
||||
dvNetworkDeviceModel = "virtio"
|
||||
dvNetworkDeviceQueues = 0
|
||||
dvNetworkDeviceRateLimit = 0
|
||||
dvNetworkDeviceVLANID = 0
|
||||
dvNetworkDeviceTrunks = ""
|
||||
dvNetworkDeviceMTU = 0
|
||||
dvNetworkDeviceVLANID = 0
|
||||
|
||||
mkIPv4Addresses = "ipv4_addresses"
|
||||
mkIPv6Addresses = "ipv6_addresses"
|
||||
mkMACAddresses = "mac_addresses"
|
||||
|
||||
// MkNetworkDevice is the name of the network device.
|
||||
MkNetworkDevice = "network_device"
|
||||
mkNetworkDeviceBridge = "bridge"
|
||||
mkNetworkDeviceEnabled = "enabled"
|
||||
mkNetworkDeviceFirewall = "firewall"
|
||||
mkNetworkDeviceMACAddress = "mac_address"
|
||||
mkNetworkDeviceModel = "model"
|
||||
mkNetworkDeviceQueues = "queues"
|
||||
mkNetworkDeviceRateLimit = "rate_limit"
|
||||
mkNetworkDeviceVLANID = "vlan_id"
|
||||
mkNetworkDeviceTrunks = "trunks"
|
||||
mkNetworkDeviceMTU = "mtu"
|
||||
mkNetworkInterfaceNames = "network_interface_names"
|
||||
MkNetworkDevice = "network_device"
|
||||
mkNetworkDeviceBridge = "bridge"
|
||||
mkNetworkDeviceDisconnected = "disconnected"
|
||||
mkNetworkDeviceEnabled = "enabled"
|
||||
mkNetworkDeviceFirewall = "firewall"
|
||||
mkNetworkDeviceMACAddress = "mac_address"
|
||||
mkNetworkDeviceMTU = "mtu"
|
||||
mkNetworkDeviceModel = "model"
|
||||
mkNetworkDeviceQueues = "queues"
|
||||
mkNetworkDeviceRateLimit = "rate_limit"
|
||||
mkNetworkDeviceTrunks = "trunks"
|
||||
mkNetworkDeviceVLANID = "vlan_id"
|
||||
mkNetworkInterfaceNames = "network_interface_names"
|
||||
)
|
||||
|
||||
// Schema returns the schema for the network resource.
|
||||
@ -86,6 +87,11 @@ func Schema() map[string]*schema.Schema {
|
||||
Optional: true,
|
||||
Default: dvNetworkDeviceBridge,
|
||||
},
|
||||
mkNetworkDeviceDisconnected: {
|
||||
Type: schema.TypeBool,
|
||||
Description: "Whether the network device should be disconnected from the network",
|
||||
Optional: true,
|
||||
},
|
||||
mkNetworkDeviceEnabled: {
|
||||
Type: schema.TypeBool,
|
||||
Description: "Whether to enable the network device",
|
||||
|
Loading…
Reference in New Issue
Block a user