0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-30 02:31:10 +00:00
terraform-provider-proxmox/fwprovider/tests/resource_vm_clone_test.go
Pavel Boldyrev 9c72e584de
fix(vm): do not overwrite cpu attributes with defaults when cloning
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
2024-04-15 23:04:53 -04:00

123 lines
3.1 KiB
Go

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package tests
import (
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)
func TestAccResourceVMCloneCPU(t *testing.T) {
te := initTestEnvironment(t)
tests := []struct {
name string
step []resource.TestStep
}{
{"copy cpu from template in full", []resource.TestStep{{
Config: te.renderConfig(`
resource "proxmox_virtual_environment_vm" "test_cpu_clone_template" {
node_name = "{{.NodeName}}"
started = false
name = "test-cpu-clone-template"
template = "true"
cpu {
cores = 2
type = "host"
}
}
resource "proxmox_virtual_environment_vm" "test_cpu_clone" {
node_name = "{{.NodeName}}"
started = false
name = "test-cpu-clone"
clone {
vm_id = proxmox_virtual_environment_vm.test_cpu_clone_template.id
}
}`),
Check: resource.ComposeTestCheckFunc(
testResourceAttributes("proxmox_virtual_environment_vm.test_cpu_clone", map[string]string{
"cpu.0.cores": "2",
"cpu.0.type": "host",
}),
),
}}},
{"merge cpu attributes", []resource.TestStep{{
Config: te.renderConfig(`
resource "proxmox_virtual_environment_vm" "test_cpu_clone_template" {
node_name = "{{.NodeName}}"
started = false
name = "test-cpu-clone-template"
template = "true"
cpu {
cores = 2
}
}
resource "proxmox_virtual_environment_vm" "test_cpu_clone" {
node_name = "{{.NodeName}}"
started = false
name = "test-cpu-clone"
cpu {
type = "host"
}
clone {
vm_id = proxmox_virtual_environment_vm.test_cpu_clone_template.id
}
}`),
Check: resource.ComposeTestCheckFunc(
testResourceAttributes("proxmox_virtual_environment_vm.test_cpu_clone", map[string]string{
"cpu.0.cores": "2",
"cpu.0.type": "host",
}),
),
}}},
{"overwrite cpu attributes in full", []resource.TestStep{{
Config: te.renderConfig(`
resource "proxmox_virtual_environment_vm" "test_cpu_clone_template" {
node_name = "{{.NodeName}}"
started = false
name = "test-cpu-clone-template"
template = "true"
}
resource "proxmox_virtual_environment_vm" "test_cpu_clone" {
node_name = "{{.NodeName}}"
started = false
name = "test-cpu-clone"
cpu {
cores = 2
type = "host"
}
clone {
vm_id = proxmox_virtual_environment_vm.test_cpu_clone_template.id
}
}`),
Check: resource.ComposeTestCheckFunc(
testResourceAttributes("proxmox_virtual_environment_vm.test_cpu_clone", map[string]string{
"cpu.0.cores": "2",
"cpu.0.type": "host",
}),
),
}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: te.accProviders,
Steps: tt.step,
})
})
}
}