0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-05 05:24:01 +00:00
terraform-provider-proxmox/proxmoxtf/provider/schema.go
Pavel Boldyrev 1f006aa82b
feat: API client cleanup and refactoring (#323)
* cleanup 1

* continue refactoring

* more refactoring

* move VMs under nodes

* move container and other apis under nodes

* cleanups

* enabled revive.exported linter & add comments to exported stuff

* enable godot linter

* enable wsl linter

* enable thelper linter

* enable govet linter

* cleanup after rebase

* cleanup after rebase

* extract SSH ops into a separate interface

* fix linter error

* move ssh code to its own package

* cleaning up VirtualEnvironmentClient receivers

* on the finish line

* not sure what else I forgot... 🤔

* fix ssh connection and upload

* renaming client interfaces

* final cleanups
2023-05-26 01:32:51 +00:00

162 lines
4.8 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 provider
import (
"fmt"
"os"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func createSchema() map[string]*schema.Schema {
providerSchema := nestedProviderSchema()
providerSchema[mkProviderVirtualEnvironment] = &schema.Schema{
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: nestedProviderSchema(),
},
MaxItems: 1,
Deprecated: "Move attributes out of virtual_environment block",
}
return providerSchema
}
func nestedProviderSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
mkProviderEndpoint: {
Type: schema.TypeString,
Optional: true,
Description: "The endpoint for the Proxmox Virtual Environment API",
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"PROXMOX_VE_ENDPOINT", "PM_VE_ENDPOINT"},
nil,
),
AtLeastOneOf: []string{
mkProviderEndpoint,
fmt.Sprintf("%s.0.%s", mkProviderVirtualEnvironment, mkProviderEndpoint),
},
ValidateFunc: validation.IsURLWithHTTPorHTTPS,
},
mkProviderInsecure: {
Type: schema.TypeBool,
Optional: true,
Description: "Whether to skip the TLS verification step",
DefaultFunc: func() (interface{}, error) {
for _, k := range []string{"PROXMOX_VE_INSECURE", "PM_VE_INSECURE"} {
v := os.Getenv(k)
if v == "true" || v == "1" {
return true, nil
}
}
return false, nil
},
},
mkProviderOTP: {
Type: schema.TypeString,
Optional: true,
Description: "The one-time password for the Proxmox Virtual Environment API",
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"PROXMOX_VE_OTP", "PM_VE_OTP"},
dvProviderOTP,
),
},
mkProviderPassword: {
Type: schema.TypeString,
Optional: true,
Description: "The password for the Proxmox Virtual Environment API",
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"PROXMOX_VE_PASSWORD", "PM_VE_PASSWORD"},
nil,
),
AtLeastOneOf: []string{
mkProviderPassword,
fmt.Sprintf("%s.0.%s", mkProviderVirtualEnvironment, mkProviderPassword),
},
ValidateFunc: validation.StringIsNotEmpty,
},
mkProviderUsername: {
Type: schema.TypeString,
Optional: true,
Description: "The username for the Proxmox Virtual Environment API",
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"PROXMOX_VE_USERNAME", "PM_VE_USERNAME"},
nil,
),
AtLeastOneOf: []string{
mkProviderUsername,
fmt.Sprintf("%s.0.%s", mkProviderVirtualEnvironment, mkProviderUsername),
},
ValidateFunc: validation.StringIsNotEmpty,
},
mkProviderSSH: {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "The SSH connection configuration to a Proxmox node",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
mkProviderSSHUsername: {
Type: schema.TypeString,
Optional: true,
Description: fmt.Sprintf("The username used for the SSH connection, "+
"defaults to the user specified in '%s'", mkProviderUsername),
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"PROXMOX_VE_SSH_USERNAME", "PM_VE_SSH_USERNAME"},
nil,
),
ValidateFunc: validation.StringIsNotEmpty,
},
mkProviderSSHPassword: {
Type: schema.TypeString,
Optional: true,
Description: fmt.Sprintf("The password used for the SSH connection, "+
"defaults to the password specified in '%s'", mkProviderPassword),
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"PROXMOX_VE_SSH_PASSWORD", "PM_VE_SSH_PASSWORD"},
nil,
),
ValidateFunc: validation.StringIsNotEmpty,
},
mkProviderSSHAgent: {
Type: schema.TypeBool,
Optional: true,
Description: "Whether to use the SSH agent for the SSH authentication. Defaults to false",
DefaultFunc: func() (interface{}, error) {
for _, k := range []string{"PROXMOX_VE_SSH_AGENT", "PM_VE_SSH_AGENT"} {
v := os.Getenv(k)
if v == "true" || v == "1" {
return true, nil
}
}
return false, nil
},
},
mkProviderSSHAgentSocket: {
Type: schema.TypeString,
Optional: true,
Description: "The path to the SSH agent socket. Defaults to the value of the `SSH_AUTH_SOCK` " +
"environment variable",
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"SSH_AUTH_SOCK", "PROXMOX_VE_SSH_AUTH_SOCK", "PM_VE_SSH_AUTH_SOCK"},
nil,
),
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
}
}