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

fix(vm): regression: mac_addresses list is missing some interfaces (#1049)

* fix(vm): regression: `mac_addresses` list is missing some interfaces

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

* add acceptance test

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

---------

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2024-02-20 21:14:48 -05:00 committed by GitHub
parent 079119444d
commit 518e25efaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 94 additions and 4 deletions

2
.vscode/launch.json vendored
View File

@ -8,7 +8,7 @@
"mode": "test",
"program": "${workspaceFolder}/fwprovider/tests",
"envFile": "${workspaceFolder}/testacc.env",
"args": ["-debug", "-test.v", "-test.timeout", "30s"]
"args": ["-debug", "-test.v", "-test.timeout", "120s"]
},
{

View File

@ -80,6 +80,93 @@ func TestAccResourceVM(t *testing.T) {
}
}
func TestAccResourceVMNetwork(t *testing.T) {
t.Parallel()
tests := []struct {
name string
step resource.TestStep
}{
{"network interfaces mac", resource.TestStep{
Config: `
resource "proxmox_virtual_environment_file" "cloud_config" {
content_type = "snippets"
datastore_id = "local"
node_name = "pve"
source_raw {
data = <<EOF
#cloud-config
runcmd:
- apt update
- apt install -y qemu-guest-agent
- systemctl enable qemu-guest-agent
- systemctl start qemu-guest-agent
EOF
file_name = "cloud-config.yaml"
}
}
resource "proxmox_virtual_environment_vm" "test_vm_network1" {
node_name = "pve"
started = true
agent {
enabled = true
}
cpu {
cores = 2
}
memory {
dedicated = 2048
}
disk {
datastore_id = "local-lvm"
file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id
interface = "virtio0"
iothread = true
discard = "on"
size = 20
}
initialization {
ip_config {
ipv4 {
address = "dhcp"
}
}
user_data_file_id = proxmox_virtual_environment_file.cloud_config.id
}
network_device {
bridge = "vmbr0"
}
}
resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" {
content_type = "iso"
datastore_id = "local"
node_name = "pve"
url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
}`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm_network1", "ipv4_addresses.#", "2"),
resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm_network1", "mac_addresses.#", "2"),
),
}},
}
accProviders := testAccMuxProviders(context.Background(), t)
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: accProviders,
Steps: []resource.TestStep{tt.step},
})
})
}
}
func TestAccResourceVMDisks(t *testing.T) {
t.Parallel()

View File

@ -518,7 +518,7 @@ func Container() *schema.Resource {
ForceNew: true,
Sensitive: true,
Default: dvInitializationUserAccountPassword,
DiffSuppressFunc: func(k, oldVal, newVal string, d *schema.ResourceData) bool {
DiffSuppressFunc: func(k, oldVal, _ string, _ *schema.ResourceData) bool {
return len(oldVal) > 0 &&
strings.ReplaceAll(oldVal, "*", "") == ""
},
@ -604,7 +604,7 @@ func Container() *schema.Resource {
// // PVE strips leading slashes from the path, so we have to do the same
// return strings.TrimPrefix(i.(string), "/")
// },
DiffSuppressFunc: func(k, oldVal, newVal string, d *schema.ResourceData) bool {
DiffSuppressFunc: func(_, oldVal, newVal string, _ *schema.ResourceData) bool {
return "/"+oldVal == newVal
},
},
@ -691,7 +691,7 @@ func Container() *schema.Resource {
Description: "The MAC address",
Optional: true,
Default: dvNetworkInterfaceMACAddress,
DiffSuppressFunc: func(k, oldVal, newVal string, d *schema.ResourceData) bool {
DiffSuppressFunc: func(_, _, newVal string, _ *schema.ResourceData) bool {
return newVal == ""
},
ValidateDiagFunc: validator.MACAddress(),

View File

@ -5169,6 +5169,9 @@ func vmReadNetworkValues(
networkInterfaceNames[ri] = rv.Name
}
}
err = d.Set(mkMACAddresses, macAddresses)
diags = append(diags, diag.FromErr(err)...)
}
}