mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-04 12:32:59 +00:00
* feat(core): add query url metadata endpoint to nodes client api Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(core): move storage api code to nodestorage folder Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(core): add download url api Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): add resource_download_file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): finish new resource_download_file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): generate docs for new download file resource, update other docs and examples Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): add basic acc tests for resource download_file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(test): lint new test file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): warning instead of error when file already exists on resource download file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): better validation in resource download file, delete upload task on error Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): better err message in resource download file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(core): removed unnecessary toint in custom type bool Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(storage): typo in resource download file error Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): download file resource review - 1 Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): finish resource download file after review Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(storage): error instead of warnings in parse int errors in sizeRequiresReplaceModifier Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(docs): remove unwanted changes in virtual_environment_file.md Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(test): fix download file base acceptance tests Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(test): fix resource download file acc tests Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(test): last fix resource download file acc test Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix: use PVE-compatible jammy LXC image, fix few typos Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: Rafał Safin <rafal.safin@rafsaf.pl> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
116 lines
3.1 KiB
Go
116 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 (
|
|
"context"
|
|
"fmt"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
|
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
|
|
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
|
|
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
|
|
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/bpg/terraform-provider-proxmox/fwprovider"
|
|
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
|
|
"github.com/bpg/terraform-provider-proxmox/proxmox/nodes"
|
|
"github.com/bpg/terraform-provider-proxmox/proxmox/nodes/storage"
|
|
sdkV2provider "github.com/bpg/terraform-provider-proxmox/proxmoxtf/provider"
|
|
"github.com/bpg/terraform-provider-proxmox/utils"
|
|
)
|
|
|
|
const (
|
|
accTestNodeName = "pve"
|
|
accTestStorageName = "local"
|
|
)
|
|
|
|
// testAccMuxProviders returns a map of mux servers for the acceptance tests.
|
|
func testAccMuxProviders(ctx context.Context, t *testing.T) map[string]func() (tfprotov6.ProviderServer, error) {
|
|
t.Helper()
|
|
|
|
// Init sdkV2 provider
|
|
sdkV2Provider, err := tf5to6server.UpgradeServer(
|
|
ctx,
|
|
func() tfprotov5.ProviderServer {
|
|
return schema.NewGRPCProviderServer(
|
|
sdkV2provider.ProxmoxVirtualEnvironment(),
|
|
)
|
|
},
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
// Init framework provider
|
|
frameworkProvider := fwprovider.New("test")()
|
|
|
|
providers := []func() tfprotov6.ProviderServer{
|
|
providerserver.NewProtocol6(frameworkProvider),
|
|
func() tfprotov6.ProviderServer {
|
|
return sdkV2Provider
|
|
},
|
|
}
|
|
|
|
// Init mux servers
|
|
muxServers := map[string]func() (tfprotov6.ProviderServer, error){
|
|
"proxmox": func() (tfprotov6.ProviderServer, error) {
|
|
muxServer, e := tf6muxserver.NewMuxServer(ctx, providers...)
|
|
if e != nil {
|
|
return nil, fmt.Errorf("failed to create mux server: %w", e)
|
|
}
|
|
return muxServer, nil
|
|
},
|
|
}
|
|
|
|
return muxServers
|
|
}
|
|
|
|
//nolint:gochecknoglobals
|
|
var (
|
|
once sync.Once
|
|
nodesClient *nodes.Client
|
|
)
|
|
|
|
func getNodesClient() *nodes.Client {
|
|
if nodesClient == nil {
|
|
once.Do(
|
|
func() {
|
|
username := utils.GetAnyStringEnv("PROXMOX_VE_USERNAME")
|
|
password := utils.GetAnyStringEnv("PROXMOX_VE_PASSWORD")
|
|
endpoint := utils.GetAnyStringEnv("PROXMOX_VE_ENDPOINT")
|
|
apiToken := utils.GetAnyStringEnv("PROXMOX_VE_API_TOKEN")
|
|
|
|
creds, err := api.NewCredentials(username, password, "", apiToken)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
conn, err := api.NewConnection(endpoint, true)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
client, err := api.NewClient(creds, conn)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
nodesClient = &nodes.Client{Client: client, NodeName: accTestNodeName}
|
|
})
|
|
}
|
|
|
|
return nodesClient
|
|
}
|
|
|
|
func getNodeStorageClient() *storage.Client {
|
|
nodesClient := getNodesClient()
|
|
return &storage.Client{Client: nodesClient, StorageName: accTestStorageName}
|
|
}
|