Skip to content

Commit

Permalink
misc(vm2): add support for vga (#1328)
Browse files Browse the repository at this point in the history
* misc(vm2): add support for `vga`
* fix: use random VM IDs in parallel acc tests

---------

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
  • Loading branch information
bpg authored May 28, 2024
1 parent e0097d9 commit d843e46
Show file tree
Hide file tree
Showing 36 changed files with 564 additions and 86 deletions.
11 changes: 11 additions & 0 deletions docs/data-sources/virtual_environment_vm2.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This is an experimental implementation of a Proxmox VM datasource using Plugin F
- `tags` (Set of String) The tags assigned to the VM.
- `template` (Boolean) Whether the VM is a template.
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))
- `vga` (Attributes) The VGA configuration. (see [below for nested schema](#nestedatt--vga))

<a id="nestedatt--clone"></a>
### Nested Schema for `clone`
Expand Down Expand Up @@ -67,3 +68,13 @@ Optional:
Optional:

- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.


<a id="nestedatt--vga"></a>
### Nested Schema for `vga`

Optional:

- `clipboard` (String) Enable a specific clipboard.
- `memory` (Number) The VGA memory in megabytes (4-512 MB). Has no effect with serial display.
- `type` (String) The VGA type.
4 changes: 2 additions & 2 deletions docs/resources/virtual_environment_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,9 @@ output "ubuntu_vm_public_key" {
- `serial3` - Serial Terminal 3.
- `std` - Standard VGA.
- `virtio` - VirtIO-GPU.
- `virtio-gl` - VirtIO-GPU with 3D acceleration (VirGL). VirGL support needs some extra libraries that aren’t installed by default. See the [Proxmox documentation](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_virtual_machines_settings) section 10.2.8.for more information.
- `virtio-gl` - VirtIO-GPU with 3D acceleration (VirGL). VirGL support needs some extra libraries that aren’t installed by default. See the [Proxmox documentation](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_virtual_machines_settings) section 10.2.8 for more information.
- `vmware` - VMware Compatible.
- `clipboard` - (Optional) Enable VNC clipboard by setting to `vnc`. See the [Proxmox documentation](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_virtual_machines_settings) section 10.2.8.for more information.
- `clipboard` - (Optional) Enable VNC clipboard by setting to `vnc`. See the [Proxmox documentation](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_virtual_machines_settings) section 10.2.8 for more information.
- `vm_id` - (Optional) The VM identifier.
- `hook_script_file_id` - (Optional) The identifier for a file containing a hook script (needs to be executable).

Expand Down
11 changes: 11 additions & 0 deletions docs/resources/virtual_environment_vm2.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The attributes are also marked as optional to allow the practitioner to set (or
- `tags` (Set of String) The tags assigned to the VM.
- `template` (Boolean) Set to true to create a VM template.
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))
- `vga` (Attributes) Configure the VGA Hardware. If you want to use high resolution modes (>= 1280x1024x16) you may need to increase the vga memory option. Since QEMU 2.9 the default VGA display type is `std` for all OS types besides some Windows versions (XP and older) which use `cirrus`. The `qxl` option enables the SPICE display server. For win* OS you can select how many independent displays you want, Linux guests can add displays themself. You can also run without any graphic card, using a serial device as terminal. See the [Proxmox documentation](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_virtual_machines_settings) section 10.2.8 for more information and available configuration parameters. (see [below for nested schema](#nestedatt--vga))

<a id="nestedatt--clone"></a>
### Nested Schema for `clone`
Expand Down Expand Up @@ -77,3 +78,13 @@ Optional:
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).


<a id="nestedatt--vga"></a>
### Nested Schema for `vga`

Optional:

- `clipboard` (String) Enable a specific clipboard. If not set, depending on the display type the SPICE one will be added. Currently only `vnc` is available. Migration with VNC clipboard is not supported by Proxmox.
- `memory` (Number) The VGA memory in megabytes (4-512 MB). Has no effect with serial display.
- `type` (String) The VGA type (defaults to `std`).
4 changes: 2 additions & 2 deletions fwprovider/access/resource_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
"github.com/bpg/terraform-provider-proxmox/proxmox"
"github.com/bpg/terraform-provider-proxmox/proxmox/helpers/ptr"
proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types"
Expand Down Expand Up @@ -54,7 +54,7 @@ func (r *aclResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
stringplanmodifier.RequiresReplace(),
},
},
"id": structure.IDAttribute(),
"id": attribute.ID(),
"path": schema.StringAttribute{
Description: "Access control path",
Required: true,
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/access/resource_user_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
"github.com/bpg/terraform-provider-proxmox/fwprovider/validators"
"github.com/bpg/terraform-provider-proxmox/proxmox"
"github.com/bpg/terraform-provider-proxmox/proxmox/access"
Expand Down Expand Up @@ -69,7 +69,7 @@ func (r *userTokenResource) Schema(
}, "must be a valid RFC3339 date"),
},
},
"id": structure.IDAttribute("Unique token identifier with format `<user_id>!<token_name>`."),
"id": attribute.ID("Unique token identifier with format `<user_id>!<token_name>`."),
"privileges_separation": schema.BoolAttribute{
Description: "Restrict API token privileges with separate ACLs (default)",
MarkdownDescription: "Restrict API token privileges with separate ACLs (default), " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package structure
package attribute

import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
)

// IDAttribute generates an attribute definition suitable for the always-present `id` attribute.
func IDAttribute(desc ...string) schema.StringAttribute {
attr := schema.StringAttribute{
// ID generates an attribute definition suitable for the always-present `id` attribute.
func ID(desc ...string) schema.StringAttribute {
a := schema.StringAttribute{
Computed: true,
Description: "The unique identifier of this resource.",
PlanModifiers: []planmodifier.String{
Expand All @@ -23,8 +24,18 @@ func IDAttribute(desc ...string) schema.StringAttribute {
}

if len(desc) > 0 {
attr.Description = desc[0]
a.Description = desc[0]
}

return attr
return a
}

// ShouldBeRemoved evaluates if an attribute should be removed from the plan during update.
func ShouldBeRemoved(plan attr.Value, state attr.Value, isClone bool) bool {
return !IsDefined(plan) && IsDefined(state) && !isClone
}

// IsDefined returns true if attribute is known and not null.
func IsDefined(v attr.Value) bool {
return !v.IsNull() && !v.IsUnknown()
}
4 changes: 2 additions & 2 deletions fwprovider/ha/datasource_hagroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"

"github.com/bpg/terraform-provider-proxmox/proxmox"
hagroups "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/groups"
Expand Down Expand Up @@ -51,7 +51,7 @@ func (d *haGroupDatasource) Schema(_ context.Context, _ datasource.SchemaRequest
resp.Schema = schema.Schema{
Description: "Retrieves information about a specific High Availability group.",
Attributes: map[string]schema.Attribute{
"id": structure.IDAttribute(),
"id": attribute.ID(),
"group": schema.StringAttribute{
Description: "The identifier of the High Availability group to read.",
Required: true,
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/ha/datasource_hagroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"

"github.com/bpg/terraform-provider-proxmox/proxmox"
hagroups "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/groups"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (d *haGroupsDatasource) Schema(_ context.Context, _ datasource.SchemaReques
resp.Schema = schema.Schema{
Description: "Retrieves the list of High Availability groups.",
Attributes: map[string]schema.Attribute{
"id": structure.IDAttribute(),
"id": attribute.ID(),
"group_ids": schema.SetAttribute{
Description: "The identifiers of the High Availability groups.",
ElementType: types.StringType,
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/ha/datasource_haresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
"github.com/bpg/terraform-provider-proxmox/proxmox"
haresources "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/resources"
proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types"
Expand Down Expand Up @@ -50,7 +50,7 @@ func (d *haResourceDatasource) Schema(_ context.Context, _ datasource.SchemaRequ
resp.Schema = schema.Schema{
Description: "Retrieves the list of High Availability resources.",
Attributes: map[string]schema.Attribute{
"id": structure.IDAttribute(),
"id": attribute.ID(),
"resource_id": schema.StringAttribute{
Description: "The identifier of the Proxmox HA resource to read.",
Required: true,
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/ha/datasource_haresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"

"github.com/bpg/terraform-provider-proxmox/proxmox"
haresources "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/resources"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (d *haResourcesDatasource) Schema(_ context.Context, _ datasource.SchemaReq
resp.Schema = schema.Schema{
Description: "Retrieves the list of High Availability resources.",
Attributes: map[string]schema.Attribute{
"id": structure.IDAttribute(),
"id": attribute.ID(),
"type": schema.StringAttribute{
Description: "The type of High Availability resources to fetch (`vm` or `ct`). All resources " +
"will be fetched if this option is unset.",
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/ha/resource_hagroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"

"github.com/bpg/terraform-provider-proxmox/proxmox"
hagroups "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/groups"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (r *hagroupResource) Schema(
resp.Schema = schema.Schema{
Description: "Manages a High Availability group in a Proxmox VE cluster.",
Attributes: map[string]schema.Attribute{
"id": structure.IDAttribute(),
"id": attribute.ID(),
"group": schema.StringAttribute{
Description: "The identifier of the High Availability group to manage.",
Required: true,
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/ha/resource_haresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"regexp"
"strings"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
"github.com/bpg/terraform-provider-proxmox/proxmox"
haresources "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/resources"
proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types"
Expand Down Expand Up @@ -68,7 +68,7 @@ func (r *haResourceResource) Schema(
resp.Schema = schema.Schema{
Description: "Manages Proxmox HA resources.",
Attributes: map[string]schema.Attribute{
"id": structure.IDAttribute(),
"id": attribute.ID(),
"resource_id": schema.StringAttribute{
Description: "The Proxmox HA resource identifier",
Required: true,
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/hardwaremapping/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
"github.com/bpg/terraform-provider-proxmox/proxmox"
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/mapping"
proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types/hardwaremapping"
Expand Down Expand Up @@ -179,7 +179,7 @@ func (d *dataSource) Schema(
Computed: true,
Description: "The identifiers of the hardware mappings.",
},
schemaAttrNameTerraformID: structure.IDAttribute(
schemaAttrNameTerraformID: attribute.ID(
"The unique identifier of this hardware mappings data source.",
),
schemaAttrNameType: schema.StringAttribute{
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/hardwaremapping/datasource_pci.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types/hardwaremapping"
"github.com/bpg/terraform-provider-proxmox/fwprovider/validators"
"github.com/bpg/terraform-provider-proxmox/proxmox"
Expand Down Expand Up @@ -155,7 +155,7 @@ func (d *dataSourcePCI) Schema(_ context.Context, _ datasource.SchemaRequest, re
Description: "The name of this PCI hardware mapping.",
Required: true,
},
schemaAttrNameTerraformID: structure.IDAttribute(
schemaAttrNameTerraformID: attribute.ID(
"The unique identifier of this PCI hardware mapping data source.",
),
},
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/hardwaremapping/datasource_usb.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types/hardwaremapping"
"github.com/bpg/terraform-provider-proxmox/fwprovider/validators"
"github.com/bpg/terraform-provider-proxmox/proxmox"
Expand Down Expand Up @@ -137,7 +137,7 @@ func (d *datasourceUSB) Schema(_ context.Context, _ datasource.SchemaRequest, re
Description: "The name of this USB hardware mapping.",
Required: true,
},
schemaAttrNameTerraformID: structure.IDAttribute(
schemaAttrNameTerraformID: attribute.ID(
"The unique identifier of this USB hardware mapping data source.",
),
},
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/hardwaremapping/resource_pci.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types/hardwaremapping"
"github.com/bpg/terraform-provider-proxmox/fwprovider/validators"
"github.com/bpg/terraform-provider-proxmox/proxmox"
Expand Down Expand Up @@ -264,7 +264,7 @@ func (r *resourcePCI) Schema(_ context.Context, _ resource.SchemaRequest, resp *
Description: "The name of this PCI hardware mapping.",
Required: true,
},
schemaAttrNameTerraformID: structure.IDAttribute(
schemaAttrNameTerraformID: attribute.ID(
"The unique identifier of this PCI hardware mapping resource.",
),
},
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/hardwaremapping/resource_usb.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types/hardwaremapping"
"github.com/bpg/terraform-provider-proxmox/fwprovider/validators"
"github.com/bpg/terraform-provider-proxmox/proxmox"
Expand Down Expand Up @@ -249,7 +249,7 @@ func (r *resourceUSB) Schema(_ context.Context, _ resource.SchemaRequest, resp *
Description: "The name of this hardware mapping.",
Required: true,
},
schemaAttrNameTerraformID: structure.IDAttribute(
schemaAttrNameTerraformID: attribute.ID(
"The unique identifier of this USB hardware mapping resource.",
),
},
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/network/resource_linux_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types"

"github.com/bpg/terraform-provider-proxmox/proxmox"
Expand Down Expand Up @@ -173,7 +173,7 @@ func (r *linuxBridgeResource) Schema(
Description: "Manages a Linux Bridge network interface in a Proxmox VE node.",
Attributes: map[string]schema.Attribute{
// Base attributes
"id": structure.IDAttribute("A unique identifier with format `<node name>:<iface>`"),
"id": attribute.ID("A unique identifier with format `<node name>:<iface>`"),
"node_name": schema.StringAttribute{
Description: "The name of the node.",
Required: true,
Expand Down
4 changes: 2 additions & 2 deletions fwprovider/network/resource_linux_vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types"

"github.com/bpg/terraform-provider-proxmox/proxmox"
Expand Down Expand Up @@ -146,7 +146,7 @@ func (r *linuxVLANResource) Schema(
Description: "Manages a Linux VLAN network interface in a Proxmox VE node.",
Attributes: map[string]schema.Attribute{
// Base attributes
"id": structure.IDAttribute("A unique identifier with format `<node name>:<iface>`."),
"id": attribute.ID("A unique identifier with format `<node name>:<iface>`."),
"node_name": schema.StringAttribute{
Description: "The name of the node.",
Required: true,
Expand Down
Loading

0 comments on commit d843e46

Please sign in to comment.