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

fix(vm): add validation for node_name values (#1659)

* fix(vm): add validation for `node_name` values

Also, fix acceptance tests that now fail on PVE 8.3

---------

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2024-11-27 21:23:27 -05:00 committed by GitHub
parent 44c1ac7988
commit 106bcd2ff9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 9 deletions

View File

@ -28,13 +28,13 @@ func TestAccDatasourceVersion(t *testing.T) {
{
Config: `data "proxmox_virtual_environment_version" "test" {}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(datasourceName, "release", "8.2"),
resource.TestCheckResourceAttr(datasourceName, "release", "8.3"),
resource.TestCheckResourceAttrSet(datasourceName, "repository_id"),
resource.TestCheckResourceAttrWith(datasourceName, "version", func(value string) error {
if strings.HasPrefix(value, "8.2") {
if strings.HasPrefix(value, "8.3") {
return nil
}
return fmt.Errorf("version %s does not start with 8.2", value)
return fmt.Errorf("version %s does not start with 8.3", value)
}),
resource.TestCheckResourceAttrSet(datasourceName, "id"),
),

View File

@ -204,9 +204,9 @@ func TestAccResourceVMDisks(t *testing.T) {
}`),
Check: ResourceAttributes("proxmox_virtual_environment_vm.test_disk", map[string]string{
"disk.0.interface": "virtio0",
"disk.0.path_in_datastore": `vm-\d+-disk-1`,
"disk.0.path_in_datastore": `base-\d+-disk-1`,
"disk.1.interface": "scsi0",
"disk.1.path_in_datastore": `vm-\d+-disk-0`,
"disk.1.path_in_datastore": `base-\d+-disk-0`,
}),
},
{
@ -431,7 +431,7 @@ func TestAccResourceVMDisks(t *testing.T) {
"disk.0.file_format": "raw",
"disk.0.interface": "scsi0",
"disk.0.iothread": "true",
"disk.0.path_in_datastore": `vm-\d+-disk-\d+`,
"disk.0.path_in_datastore": `base-\d+-disk-\d+`,
"disk.0.size": "8",
"disk.0.ssd": "true",
}),

View File

@ -9,6 +9,7 @@
package test
import (
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@ -69,6 +70,16 @@ func TestAccResourceVM(t *testing.T) {
}),
),
}}},
{
"empty node_name", []resource.TestStep{{
Config: te.RenderConfig(`
resource "proxmox_virtual_environment_vm" "test_empty_node_name" {
node_name = ""
started = false
}`),
ExpectError: regexp.MustCompile(`expected "node_name" to not be an empty string, got `),
}},
},
{
"protection", []resource.TestStep{{
Config: te.RenderConfig(`

View File

@ -1093,9 +1093,10 @@ func VM() *schema.Resource {
Default: dvName,
},
mkNodeName: {
Type: schema.TypeString,
Description: "The node name",
Required: true,
Type: schema.TypeString,
Description: "The node name",
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
mkNUMA: {
Type: schema.TypeList,