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

fix(vm): regression: provider always tries to update memory.*hugepages even if it is not specified (#1188)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2024-04-06 08:27:55 -04:00 committed by GitHub
parent c1c4cf159b
commit 31b6812ce2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 73 additions and 14 deletions

View File

@ -35,7 +35,9 @@ func TestAccResourceVM(t *testing.T) {
EOT EOT
}`, }`,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm1", "description", "my\ndescription\nvalue"), testResourceAttributes("proxmox_virtual_environment_vm.test_vm1", map[string]string{
"description": "my\ndescription\nvalue",
}),
), ),
}}}, }}},
{"single line description", []resource.TestStep{{ {"single line description", []resource.TestStep{{
@ -47,7 +49,9 @@ func TestAccResourceVM(t *testing.T) {
description = "my description value" description = "my description value"
}`, }`,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm2", "description", "my description value"), testResourceAttributes("proxmox_virtual_environment_vm.test_vm2", map[string]string{
"description": "my description value",
}),
), ),
}}}, }}},
{"no description", []resource.TestStep{{ {"no description", []resource.TestStep{{
@ -59,7 +63,9 @@ func TestAccResourceVM(t *testing.T) {
description = "" description = ""
}`, }`,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm3", "description", ""), testResourceAttributes("proxmox_virtual_environment_vm.test_vm3", map[string]string{
"description": "",
}),
), ),
}}}, }}},
{ {
@ -72,7 +78,9 @@ func TestAccResourceVM(t *testing.T) {
protection = true protection = true
}`, }`,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm4", "protection", "true"), testResourceAttributes("proxmox_virtual_environment_vm.test_vm4", map[string]string{
"protection": "true",
}),
), ),
}, { }, {
Config: ` Config: `
@ -83,12 +91,14 @@ func TestAccResourceVM(t *testing.T) {
protection = false protection = false
}`, }`,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm4", "protection", "false"), testResourceAttributes("proxmox_virtual_environment_vm.test_vm4", map[string]string{
"protection": "false",
}),
), ),
}}, }},
}, },
{ {
"update CPU block", []resource.TestStep{{ "update cpu block", []resource.TestStep{{
Config: ` Config: `
resource "proxmox_virtual_environment_vm" "test_vm5" { resource "proxmox_virtual_environment_vm" "test_vm5" {
node_name = "pve" node_name = "pve"
@ -99,7 +109,9 @@ func TestAccResourceVM(t *testing.T) {
} }
}`, }`,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm5", "cpu.0.cores", "2"), testResourceAttributes("proxmox_virtual_environment_vm.test_vm5", map[string]string{
"cpu.0.sockets": "1",
}),
), ),
}, { }, {
Config: ` Config: `
@ -112,7 +124,42 @@ func TestAccResourceVM(t *testing.T) {
} }
}`, }`,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm5", "cpu.0.cores", "1"), testResourceAttributes("proxmox_virtual_environment_vm.test_vm5", map[string]string{
"cpu.0.sockets": "1",
}),
),
}},
},
{
"update memory block", []resource.TestStep{{
Config: `
resource "proxmox_virtual_environment_vm" "test_vm6" {
node_name = "pve"
started = false
memory {
dedicated = 2048
}
}`,
Check: resource.ComposeTestCheckFunc(
testResourceAttributes("proxmox_virtual_environment_vm.test_vm6", map[string]string{
"memory.0.dedicated": "2048",
}),
),
}, {
Config: `
resource "proxmox_virtual_environment_vm" "test_vm6" {
node_name = "pve"
started = false
memory {
dedicated = 1024
}
}`,
Check: resource.ComposeTestCheckFunc(
testResourceAttributes("proxmox_virtual_environment_vm.test_vm6", map[string]string{
"memory.0.dedicated": "1024",
}),
), ),
}}, }},
}, },
@ -496,6 +543,7 @@ func TestAccResourceVMDisks(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
// fully cloned disk, does not have any attributes in state // fully cloned disk, does not have any attributes in state
resource.TestCheckNoResourceAttr("proxmox_virtual_environment_vm.test_disk3", "disk.0"), resource.TestCheckNoResourceAttr("proxmox_virtual_environment_vm.test_disk3", "disk.0"),
testResourceAttributes("proxmox_virtual_environment_vm.test_disk3", map[string]string{}),
), ),
}, },
{ {

View File

@ -5013,12 +5013,20 @@ func vmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D
} }
} }
if memoryHugepages != "" { if d.HasChange(mkMemory + ".0." + mkMemoryHugepages) {
updateBody.Hugepages = &memoryHugepages if memoryHugepages != "" {
updateBody.KeepHugepages = &memoryKeepHugepages updateBody.Hugepages = &memoryHugepages
} else { } else {
del = append(del, "hugepages") del = append(del, "hugepages")
del = append(del, "keephugepages") }
}
if d.HasChange(mkMemory + ".0." + mkMemoryKeepHugepages) {
if memoryHugepages != "" {
updateBody.KeepHugepages = &memoryKeepHugepages
} else {
del = append(del, "keephugepages")
}
} }
rebootRequired = true rebootRequired = true

3
testacc Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
TF_ACC=1 env $(cat testacc.env | xargs) go test -v -timeout 120s -run "$1" github.com/bpg/terraform-provider-proxmox/fwprovider/tests $2