0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-30 02:31:10 +00:00

fix(provider): User-settable VLAN ID and name (#518)

* fix(provider): User-settable VLAN ID and name

By default resource `proxmox_virtual_environment_network_linux_vlan`
uses `name` to determine both the actual raw device for VLAN and
VLAN ID.

Since ifupdown2 (manually installed on PVE6, installed by default
since PVE7), it is possible to have VLAN name not tied to VLAN ID.

Make `interface` and `vlan` configurable by user.

* fix: update schema to ensure the correct docs generation.

---------

Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Oto Petřík 2023-08-29 02:19:10 +02:00 committed by GitHub
parent 60f59c6e13
commit 5599c7afe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 13 deletions

View File

@ -14,12 +14,23 @@ Manages a Linux VLAN network interface in a Proxmox VE node.
## Example Usage
```terraform
# using VLAN tag
resource "proxmox_virtual_environment_network_linux_vlan" "vlan99" {
node_name = "pve"
name = "eno0.99"
comment = "VLAN 99"
}
# using custom network interface name
resource "proxmox_virtual_environment_network_linux_vlan" "vlan98" {
node_name = "pve"
name = "vlan_lab"
interface = "eno0"
vlan = 98
comment = "VLAN 98"
}
```
<!-- schema generated by tfplugindocs -->
@ -27,7 +38,7 @@ resource "proxmox_virtual_environment_network_linux_vlan" "vlan99" {
### Required
- `name` (String) The interface name. Add the VLAN tag number to an existing interface name, e.g. `ens18.21`
- `name` (String) The interface name. Either add the VLAN tag number to an existing interface name, e.g. `ens18.21` (and do not set `interface` and `vlan`), or use custom name, e.g. `vlan_lab` (`interface` and `vlan` are then required).
- `node_name` (String) The name of the node.
### Optional
@ -38,13 +49,13 @@ resource "proxmox_virtual_environment_network_linux_vlan" "vlan99" {
- `comment` (String) Comment for the interface.
- `gateway` (String) Default gateway address.
- `gateway6` (String) Default IPv6 gateway address.
- `interface` (String) The VLAN raw device. See also `name`.
- `mtu` (Number) The interface MTU.
- `vlan` (Number) The VLAN tag. See also `name`.
### Read-Only
- `id` (String) A unique identifier with format '<node name>:<iface>'
- `interface` (String) The VLAN raw device.
- `vlan` (Number) The VLAN tag
- `id` (String) A unique identifier with format '<node name>:<iface>'.
## Import

View File

@ -1,6 +1,17 @@
# using VLAN tag
resource "proxmox_virtual_environment_network_linux_vlan" "vlan99" {
node_name = "pve"
name = "eno0.99"
comment = "VLAN 99"
}
# using custom network interface name
resource "proxmox_virtual_environment_network_linux_vlan" "vlan98" {
node_name = "pve"
name = "vlan_lab"
interface = "eno0"
vlan = 98
comment = "VLAN 98"
}

View File

@ -148,16 +148,18 @@ func (r *linuxVLANResource) Schema(
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Description: "A unique identifier with format '<node name>:<iface>'",
Description: "A unique identifier with format '<node name>:<iface>'.",
},
"node_name": schema.StringAttribute{
Description: "The name of the node.",
Required: true,
},
"name": schema.StringAttribute{
Description: "The interface name.",
MarkdownDescription: "The interface name. Add the VLAN tag number to an existing interface name, e.g. `ens18.21`",
Required: true,
Description: "The interface name.",
MarkdownDescription: "The interface name. Either add the VLAN tag number to an existing interface name, " +
"e.g. `ens18.21` (and do not set `interface` and `vlan`), or use custom name, e.g. `vlan_lab` " +
"(`interface` and `vlan` are then required).",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(3),
},
@ -202,13 +204,13 @@ func (r *linuxVLANResource) Schema(
},
// Linux VLAN attributes
"interface": schema.StringAttribute{
// read-only
Description: "The VLAN raw device.",
Description: "The VLAN raw device. See also `name`.",
Optional: true,
Computed: true,
},
"vlan": schema.Int64Attribute{
// read-only
Description: "The VLAN tag",
Description: "The VLAN tag. See also `name`.",
Optional: true,
Computed: true,
},
},

View File

@ -76,7 +76,7 @@ type NetworkInterfaceCreateUpdateRequestBody struct {
OVSPorts *string `json:"ovs_ports,omitempty" url:"ovs_ports,omitempty"`
OVSTag *string `json:"ovs_tag,omitempty" url:"ovs_tag,omitempty"`
Slaves *string `json:"slaves,omitempty" url:"slaves,omitempty"`
VLANID *int64 `json:"vlan_id,omitempty" url:"vlan_id,omitempty"`
VLANID *int64 `json:"vlan-id,omitempty" url:"vlan-id,omitempty"`
VLANRawDevice *string `json:"vlan-raw-device,omitempty" url:"vlan-raw-device,omitempty"`
}