Skip to content

Commit

Permalink
fix(vm): regression: mac_addresses list is missing some interfaces (#…
Browse files Browse the repository at this point in the history
…1049)

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

Signed-off-by: Pavel Boldyrev <[email protected]>

* add acceptance test

Signed-off-by: Pavel Boldyrev <[email protected]>

---------

Signed-off-by: Pavel Boldyrev <[email protected]>
  • Loading branch information
bpg authored Feb 21, 2024
1 parent 0791194 commit 518e25e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

},
{
Expand Down
87 changes: 87 additions & 0 deletions fwprovider/tests/resource_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions proxmoxtf/resource/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "*", "") == ""
},
Expand Down Expand Up @@ -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
},
},
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions proxmoxtf/resource/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5169,6 +5169,9 @@ func vmReadNetworkValues(
networkInterfaceNames[ri] = rv.Name
}
}

err = d.Set(mkMACAddresses, macAddresses)
diags = append(diags, diag.FromErr(err)...)
}
}

Expand Down

0 comments on commit 518e25e

Please sign in to comment.