From a0d9300f0ff1f49b4df08691f4c2286b276f84b5 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Mon, 24 Jun 2024 23:08:59 -0400 Subject: [PATCH] chore: refactor container acc test (#1408) + beautify test output on CI --------- Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- .github/workflows/test.yml | 14 +- .github/workflows/testacc.yml | 11 +- .golangci.yml | 6 +- Makefile | 2 +- fwprovider/access/resource_acl_test.go | 2 + fwprovider/access/resource_user_test.go | 2 + .../resource_hardware_mapping_test.go | 2 + .../network/resource_linux_bridge_test.go | 2 + .../network/resource_linux_vlan_test.go | 2 + fwprovider/resource_download_file_test.go | 2 + fwprovider/resource_options_test.go | 2 + fwprovider/test/datasource_node_test.go | 2 + fwprovider/test/datasource_version_test.go | 2 + fwprovider/test/resource_container_test.go | 362 +++++++++++------- fwprovider/test/resource_file_test.go | 2 + fwprovider/test/resource_firewall_test.go | 2 + fwprovider/test/resource_time_test.go | 2 + fwprovider/test/resource_vm_cdrom_test.go | 2 + fwprovider/test/resource_vm_disks_test.go | 2 + fwprovider/test/resource_vm_test.go | 2 + fwprovider/test/test_environment.go | 24 +- fwprovider/vm/cdrom/resource_test.go | 2 + fwprovider/vm/cpu/resource_test.go | 8 + fwprovider/vm/resource_test.go | 2 + fwprovider/vm/vga/resource_test.go | 8 + proxmoxtf/resource/container/container.go | 12 +- 26 files changed, 333 insertions(+), 148 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aac42465..ebe6064b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,11 +73,21 @@ jobs: if: ${{ steps.filter.outputs.go == 'true' }} run: go mod download + - name: Set up gotestfmt + run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest + - name: Unit tests if: ${{ steps.filter.outputs.go == 'true' }} timeout-minutes: 10 - run: go test -v -cover ./... + run: go test -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt -hide empty-packages + + - name: Upload test log + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-log + path: /tmp/gotest.log + if-no-files-found: error - name: Check for uncommitted changes in generated docs run: make docs && git diff --exit-code - diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 82d0bd5c..a7749c08 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -69,4 +69,13 @@ jobs: PROXMOX_VE_ACC_NODE_SSH_PORT: ${{ matrix.port }} PROXMOX_VE_ACC_CLOUD_IMAGES_SERVER: ${{ secrets.PROXMOX_VE_ACC_CLOUD_IMAGES_SERVER }} PROXMOX_VE_ACC_CONTAINER_IMAGES_SERVER: ${{ secrets.PROXMOX_VE_ACC_CONTAINER_IMAGES_SERVER }} - run: make testacc + run: + go test -json --timeout=30m --tags=acceptance -count=1 -v github.com/bpg/terraform-provider-proxmox/fwprovider/... 2>&1 | tee /tmp/gotest.log | gotestfmt -hide empty-packages + + - name: Upload test log + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-log + path: /tmp/gotest.log + if-no-files-found: error diff --git a/.golangci.yml b/.golangci.yml index 3e56c6f2..36e6a07f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,14 +11,14 @@ issues: - EXC0012 - EXC0014 exclude-rules: - # Exclude duplicate code and function length and complexity checking in test - # files (due to common repeats and long functions in test code) + # Exclude some checks in tests - path: _(test|gen)\.go linters: - cyclop - dupl - - gocognit - funlen + - gocognit + - gosec - lll - path: _types\.go linters: diff --git a/Makefile b/Makefile index 7b786726..3e377780 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,7 @@ test: .PHONY: testacc testacc: @# explicitly add TF_ACC=1 to trigger the acceptance tests, `testacc.env` might be missing or incomplete - @TF_ACC=1 env $$(cat testacc.env | xargs) go test --timeout=30m -count=1 -v github.com/bpg/terraform-provider-proxmox/fwprovider/... + @TF_ACC=1 env $$(cat testacc.env | xargs) go test --timeout=30m --tags=acceptance -count=1 -v github.com/bpg/terraform-provider-proxmox/fwprovider/... .PHONY: lint lint: diff --git a/fwprovider/access/resource_acl_test.go b/fwprovider/access/resource_acl_test.go index 2a3b5854..a516c465 100644 --- a/fwprovider/access/resource_acl_test.go +++ b/fwprovider/access/resource_acl_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/access/resource_user_test.go b/fwprovider/access/resource_user_test.go index d540a4e2..0fa1228b 100644 --- a/fwprovider/access/resource_user_test.go +++ b/fwprovider/access/resource_user_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/hardwaremapping/resource_hardware_mapping_test.go b/fwprovider/hardwaremapping/resource_hardware_mapping_test.go index cc08abe8..45aab933 100644 --- a/fwprovider/hardwaremapping/resource_hardware_mapping_test.go +++ b/fwprovider/hardwaremapping/resource_hardware_mapping_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/network/resource_linux_bridge_test.go b/fwprovider/network/resource_linux_bridge_test.go index b75e7a4b..0199aaca 100644 --- a/fwprovider/network/resource_linux_bridge_test.go +++ b/fwprovider/network/resource_linux_bridge_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/network/resource_linux_vlan_test.go b/fwprovider/network/resource_linux_vlan_test.go index 19e28c94..adfd2db7 100644 --- a/fwprovider/network/resource_linux_vlan_test.go +++ b/fwprovider/network/resource_linux_vlan_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/resource_download_file_test.go b/fwprovider/resource_download_file_test.go index 76d45c1a..45effc86 100644 --- a/fwprovider/resource_download_file_test.go +++ b/fwprovider/resource_download_file_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/resource_options_test.go b/fwprovider/resource_options_test.go index 280372b3..dcccd741 100644 --- a/fwprovider/resource_options_test.go +++ b/fwprovider/resource_options_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/datasource_node_test.go b/fwprovider/test/datasource_node_test.go index b27a45e6..8dad617b 100644 --- a/fwprovider/test/datasource_node_test.go +++ b/fwprovider/test/datasource_node_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/datasource_version_test.go b/fwprovider/test/datasource_version_test.go index 7cea27b7..c52d3f4a 100644 --- a/fwprovider/test/datasource_version_test.go +++ b/fwprovider/test/datasource_version_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/resource_container_test.go b/fwprovider/test/resource_container_test.go index bcb95497..b838fbae 100644 --- a/fwprovider/test/resource_container_test.go +++ b/fwprovider/test/resource_container_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 @@ -13,146 +15,248 @@ import ( "testing" "time" + "github.com/brianvoe/gofakeit/v7" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/stretchr/testify/require" + + "github.com/bpg/terraform-provider-proxmox/proxmox/helpers/ptr" + "github.com/bpg/terraform-provider-proxmox/proxmox/nodes/storage" ) const ( accTestContainerName = "proxmox_virtual_environment_container.test_container" ) -//nolint:gochecknoglobals -var ( - accTestContainerID = 100000 + rand.Intn(99999) //nolint:gosec - accCloneContainerID = 200000 + rand.Intn(99999) //nolint:gosec -) - -func TestAccResourceContainer(t *testing.T) { //nolint:wsl - // download fails with 404 or "exit code 8" if run in parallel - // t.Parallel() +func TestAccResourceContainer(t *testing.T) { + t.Parallel() te := InitEnvironment(t) - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: te.AccProviders, - Steps: []resource.TestStep{ - { - Config: te.RenderConfig(testAccResourceContainerCreateConfig(te, false)), - Check: testAccResourceContainerCreateCheck(te), - }, - { - Config: te.RenderConfig(testAccResourceContainerCreateConfig(te, true) + testAccResourceContainerCreateCloneConfig(te)), - Check: testAccResourceContainerCreateCloneCheck(te), - }, - }, + imageFileName := gofakeit.Word() + "-ubuntu-23.04-standard_23.04-1_amd64.tar.zst" + accTestContainerID := 100000 + rand.Intn(99999) + accTestContainerIDClone := 100000 + rand.Intn(99999) + + te.AddTemplateVars(map[string]interface{}{ + "ImageFileName": imageFileName, + "TestContainerID": accTestContainerID, + "TestContainerIDClone": accTestContainerIDClone, }) -} - -func testAccResourceContainerCreateConfig(te *Environment, isTemplate bool) string { - te.t.Helper() - - return fmt.Sprintf(` -resource "proxmox_virtual_environment_download_file" "ubuntu_container_template" { - content_type = "vztmpl" - datastore_id = "local" - node_name = "{{.NodeName}}" - url = "{{.ContainerImagesServer}}/images/system/ubuntu-23.04-standard_23.04-1_amd64.tar.zst" - overwrite_unmanaged = true -} -resource "proxmox_virtual_environment_container" "test_container" { - node_name = "{{.NodeName}}" - vm_id = %d - template = %t - - disk { - datastore_id = "local-lvm" - size = 4 - } - - mount_point { - volume = "local-lvm" - size = "4G" - path = "mnt/local" - } - - description = <<-EOT - my - description - value - EOT - - initialization { - hostname = "test" - - ip_config { - ipv4 { - address = "dhcp" - } - } - } - - network_interface { - name = "vmbr0" - } - - operating_system { - template_file_id = proxmox_virtual_environment_download_file.ubuntu_container_template.id - type = "ubuntu" - } -} -`, accTestContainerID, isTemplate) -} - -func testAccResourceContainerCreateCheck(te *Environment) resource.TestCheckFunc { - te.t.Helper() - - return resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(accTestContainerName, "description", "my\ndescription\nvalue\n"), - func(*terraform.State) error { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - err := te.NodeClient().Container(accTestContainerID).WaitForContainerStatus(ctx, "running") - require.NoError(te.t, err, "container did not start") - - return nil - }, - ) -} - -func testAccResourceContainerCreateCloneConfig(te *Environment) string { - te.t.Helper() - - return fmt.Sprintf(` -resource "proxmox_virtual_environment_container" "test_container_clone" { - depends_on = [proxmox_virtual_environment_container.test_container] - node_name = "{{.NodeName}}" - vm_id = %d - - clone { - vm_id = proxmox_virtual_environment_container.test_container.id - } - - initialization { - hostname = "test-clone" - } -} -`, accCloneContainerID) -} - -func testAccResourceContainerCreateCloneCheck(te *Environment) resource.TestCheckFunc { - te.t.Helper() - - return resource.ComposeTestCheckFunc( - func(*terraform.State) error { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - err := te.NodeClient().Container(accCloneContainerID).WaitForContainerStatus(ctx, "running") - require.NoError(te.t, err, "container did not start") - - return nil - }, - ) + + err := te.NodeStorageClient().DownloadFileByURL(context.Background(), &storage.DownloadURLPostRequestBody{ + Content: ptr.Ptr("vztmpl"), + FileName: ptr.Ptr(imageFileName), + Node: ptr.Ptr(te.NodeName), + Storage: ptr.Ptr(te.DatastoreID), + URL: ptr.Ptr(fmt.Sprintf("%s/images/system/ubuntu-23.04-standard_23.04-1_amd64.tar.zst", te.ContainerImagesServer)), + }) + require.NoError(t, err) + + t.Cleanup(func() { + e := te.NodeStorageClient().DeleteDatastoreFile(context.Background(), fmt.Sprintf("vztmpl/%s", imageFileName)) + require.NoError(t, e) + }) + + tests := []struct { + name string + step []resource.TestStep + }{ + {"crete and start container", []resource.TestStep{{ + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_container" "test_container" { + node_name = "{{.NodeName}}" + vm_id = {{.TestContainerID}} + disk { + datastore_id = "local-lvm" + size = 4 + } + mount_point { + volume = "local-lvm" + size = "4G" + path = "mnt/local" + } + description = <<-EOT + my + description + value + EOT + initialization { + hostname = "test" + ip_config { + ipv4 { + address = "dhcp" + } + } + } + network_interface { + name = "vmbr0" + } + operating_system { + template_file_id = "local:vztmpl/{{.ImageFileName}}" + type = "ubuntu" + } + }`), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(accTestContainerName, "description", "my\ndescription\nvalue\n"), + func(*terraform.State) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + err := te.NodeClient().Container(accTestContainerID).WaitForContainerStatus(ctx, "running") + require.NoError(te.t, err, "container did not start") + + return nil + }, + ), + }}}, + {"update mount points", []resource.TestStep{ + { + SkipFunc: func() (bool, error) { + // mount point deletion: https://github.com/bpg/terraform-provider-proxmox/issues/1392 + return true, nil + }, + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_container" "test_container" { + node_name = "{{.NodeName}}" + vm_id = {{.RandomVMID}} + started = false + disk { + datastore_id = "local-lvm" + size = 4 + } + mount_point { + volume = "local-lvm" + size = "4G" + path = "mnt/local1" + } + mount_point { + volume = "local" + size = "8G" + path = "mnt/local2" + } + initialization { + hostname = "test" + ip_config { + ipv4 { + address = "dhcp" + } + } + } + network_interface { + name = "vmbr0" + } + operating_system { + template_file_id = "local:vztmpl/{{.ImageFileName}}" + type = "ubuntu" + } + }`), + Check: ResourceAttributes("proxmox_virtual_environment_container.test_container", map[string]string{ + "mount_point.#": "2", + }), + }, + { + SkipFunc: func() (bool, error) { + // mount point deletion: https://github.com/bpg/terraform-provider-proxmox/issues/1392 + return true, nil + }, + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_container" "test_container" { + node_name = "{{.NodeName}}" + started = false + disk { + datastore_id = "local-lvm" + size = 4 + } + mount_point { + volume = "local-lvm" + size = "4G" + path = "mnt/local1" + } + initialization { + hostname = "test" + ip_config { + ipv4 { + address = "dhcp" + } + } + } + network_interface { + name = "vmbr0" + } + operating_system { + template_file_id = "local:vztmpl/{{.ImageFileName}}" + type = "ubuntu" + } + }`), + Check: ResourceAttributes("proxmox_virtual_environment_container.test_container", map[string]string{ + "mount_point.#": "2", + }), + }, + }}, + {"clone container", []resource.TestStep{{ + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_container" "test_container" { + node_name = "{{.NodeName}}" + vm_id = {{.RandomVMID}} + template = true + disk { + datastore_id = "local-lvm" + size = 4 + } + mount_point { + volume = "local-lvm" + size = "4G" + path = "mnt/local" + } + initialization { + hostname = "test" + ip_config { + ipv4 { + address = "dhcp" + } + } + } + network_interface { + name = "vmbr0" + } + operating_system { + template_file_id = "local:vztmpl/{{.ImageFileName}}" + type = "ubuntu" + } + } + resource "proxmox_virtual_environment_container" "test_container_clone" { + depends_on = [proxmox_virtual_environment_container.test_container] + node_name = "{{.NodeName}}" + vm_id = {{.TestContainerIDClone}} + + clone { + vm_id = proxmox_virtual_environment_container.test_container.id + } + + initialization { + hostname = "test-clone" + } + }`), + Check: resource.ComposeTestCheckFunc( + func(*terraform.State) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + err := te.NodeClient().Container(accTestContainerIDClone).WaitForContainerStatus(ctx, "running") + require.NoError(te.t, err, "container did not start") + + return nil + }, + ), + }}}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + ProtoV6ProviderFactories: te.AccProviders, + Steps: tt.step, + }) + }) + } } diff --git a/fwprovider/test/resource_file_test.go b/fwprovider/test/resource_file_test.go index 62bc5488..96ac0035 100644 --- a/fwprovider/test/resource_file_test.go +++ b/fwprovider/test/resource_file_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/resource_firewall_test.go b/fwprovider/test/resource_firewall_test.go index b368e511..a875b866 100644 --- a/fwprovider/test/resource_firewall_test.go +++ b/fwprovider/test/resource_firewall_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/resource_time_test.go b/fwprovider/test/resource_time_test.go index 9e7dce4b..4f89543a 100644 --- a/fwprovider/test/resource_time_test.go +++ b/fwprovider/test/resource_time_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/resource_vm_cdrom_test.go b/fwprovider/test/resource_vm_cdrom_test.go index 9de19bbf..cd4dad80 100644 --- a/fwprovider/test/resource_vm_cdrom_test.go +++ b/fwprovider/test/resource_vm_cdrom_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/resource_vm_disks_test.go b/fwprovider/test/resource_vm_disks_test.go index 2c638bb8..62981d43 100644 --- a/fwprovider/test/resource_vm_disks_test.go +++ b/fwprovider/test/resource_vm_disks_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/resource_vm_test.go b/fwprovider/test/resource_vm_test.go index adb886f3..e0b4a357 100644 --- a/fwprovider/test/resource_vm_test.go +++ b/fwprovider/test/resource_vm_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/test/test_environment.go b/fwprovider/test/test_environment.go index 11dc8dd7..8c508ce9 100644 --- a/fwprovider/test/test_environment.go +++ b/fwprovider/test/test_environment.go @@ -1,3 +1,9 @@ +/* + * 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 test import ( @@ -36,9 +42,11 @@ type Environment struct { NodeName string DatastoreID string - AccProviders map[string]func() (tfprotov6.ProviderServer, error) - once sync.Once - c api.Client + AccProviders map[string]func() (tfprotov6.ProviderServer, error) + once sync.Once + c api.Client + CloudImagesServer string + ContainerImagesServer string } // InitEnvironment initializes a new test environment for acceptance tests. @@ -97,10 +105,12 @@ provider "proxmox" { "CloudImagesServer": cloudImagesServer, "ContainerImagesServer": containerImagesServer, }, - providerConfig: pc, - NodeName: nodeName, - DatastoreID: datastoreID, - AccProviders: muxProviders(t), + providerConfig: pc, + NodeName: nodeName, + DatastoreID: datastoreID, + AccProviders: muxProviders(t), + CloudImagesServer: cloudImagesServer, + ContainerImagesServer: containerImagesServer, } } diff --git a/fwprovider/vm/cdrom/resource_test.go b/fwprovider/vm/cdrom/resource_test.go index 5f6724f4..12b91d8b 100644 --- a/fwprovider/vm/cdrom/resource_test.go +++ b/fwprovider/vm/cdrom/resource_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/vm/cpu/resource_test.go b/fwprovider/vm/cpu/resource_test.go index 7ae98260..eaa0de42 100644 --- a/fwprovider/vm/cpu/resource_test.go +++ b/fwprovider/vm/cpu/resource_test.go @@ -1,3 +1,11 @@ +//go:build acceptance || all + +/* + * 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 cpu_test import ( diff --git a/fwprovider/vm/resource_test.go b/fwprovider/vm/resource_test.go index dea698dc..a6ef10a9 100644 --- a/fwprovider/vm/resource_test.go +++ b/fwprovider/vm/resource_test.go @@ -1,3 +1,5 @@ +//go:build acceptance || all + /* * 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 diff --git a/fwprovider/vm/vga/resource_test.go b/fwprovider/vm/vga/resource_test.go index b4ee4be4..831e913d 100644 --- a/fwprovider/vm/vga/resource_test.go +++ b/fwprovider/vm/vga/resource_test.go @@ -1,3 +1,11 @@ +//go:build acceptance || all + +/* + * 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 vga_test import ( diff --git a/proxmoxtf/resource/container/container.go b/proxmoxtf/resource/container/container.go index 234a4568..6575c08f 100644 --- a/proxmoxtf/resource/container/container.go +++ b/proxmoxtf/resource/container/container.go @@ -2831,13 +2831,15 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) // Prepare the new mount point configuration. if d.HasChange(mkMountPoint) { - mountPoint := d.Get(mkMountPoint).([]interface{}) + _, newMountPoints := d.GetChange(mkMountPoint) + + mountPoints := newMountPoints.([]interface{}) mountPointArray := make( containers.CustomMountPointArray, - len(mountPoint), + len(mountPoints), ) - for i, mp := range mountPoint { + for i, mp := range mountPoints { mountPointMap := mp.(map[string]interface{}) mountPointObject := containers.CustomMountPoint{} @@ -2861,7 +2863,7 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) mountPointObject.Volume = volume if len(mountOptions) > 0 { - mountOptionsArray := make([]string, 0, len(mountPoint)) + mountOptionsArray := make([]string, 0, len(mountPoints)) for _, option := range mountOptions { mountOptionsArray = append(mountOptionsArray, option.(string)) @@ -3040,7 +3042,7 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) } // As a final step in the update procedure, we might need to reboot the container. - if !bool(template) && rebootRequired { + if !bool(template) && started && rebootRequired { rebootTimeout := 300 e = containerAPI.RebootContainer(