mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-10 07:45:02 +00:00
Initial support for environment variables
This commit is contained in:
parent
1cf307cec0
commit
d08416630b
26
README.md
26
README.md
@ -35,6 +35,32 @@ If you're building the provider, follow the instructions to [install it as a plu
|
||||
* `password` - (Required) The password for the Proxmox Virtual Environment API
|
||||
* `username` - (Required) The username for the Proxmox Virtual Environment API
|
||||
|
||||
#### Environment variables
|
||||
You can set up the provider by passing environment variables instead of specifying arguments.
|
||||
|
||||
* `PROXMOX_VE_ENDPOINT` or `PM_VE_ENDPOINT` - The endpoint for the Proxmox Virtual Environment API
|
||||
* `PROXMOX_VE_INSECURE` or `PM_VE_INSECURE` - Whether to skip the TLS verification step
|
||||
* `PROXMOX_VE_PASSWORD` or `PM_VE_PASSWORD` - The password for the Proxmox Virtual Environment API
|
||||
* `PROXMOX_VE_USERNAME` or `PM_VE_USERNAME` - The username for the Proxmox Virtual Environment API
|
||||
|
||||
```hcl
|
||||
provider "proxmox" {
|
||||
virtual_environment {}
|
||||
}
|
||||
```
|
||||
|
||||
##### Usage
|
||||
|
||||
```
|
||||
export PROXMOX_VE_ENDPOINT="https://hostname:8006"
|
||||
export PROXMOX_VE_INSECURE="true"
|
||||
export PROXMOX_VE_PASSWORD="a-strong-password"
|
||||
export PROXMOX_VE_USERNAME="username@realm"
|
||||
terraform plan
|
||||
```
|
||||
|
||||
You can omit `PROXMOX_VE_INSECURE`, if the Proxmox Virtual Environment API is exposing a certificate trusted by your operating system.
|
||||
|
||||
### Data Sources
|
||||
|
||||
#### Virtual Environment
|
||||
|
@ -6,6 +6,8 @@ package proxmoxtf
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/danitso/terraform-provider-proxmox/proxmox"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
@ -55,24 +57,87 @@ func Provider() *schema.Provider {
|
||||
Schema: map[string]*schema.Schema{
|
||||
mkProviderVirtualEnvironmentEndpoint: {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
Description: "The endpoint for the Proxmox Virtual Environment API",
|
||||
DefaultFunc: schema.MultiEnvDefaultFunc(
|
||||
[]string{"PROXMOX_VE_ENDPOINT", "PM_VE_ENDPOINT"},
|
||||
"",
|
||||
),
|
||||
ValidateFunc: func(v interface{}, k string) (warns []string, errs []error) {
|
||||
value := v.(string)
|
||||
|
||||
if value == "" {
|
||||
return []string{}, []error{
|
||||
errors.New("You must specify an endpoint for the Proxmox Virtual Environment API (valid: https://host:port)"),
|
||||
}
|
||||
}
|
||||
|
||||
_, err := url.ParseRequestURI(value)
|
||||
|
||||
if err != nil {
|
||||
return []string{}, []error{
|
||||
errors.New("You must specify a valid endpoint for the Proxmox Virtual Environment API (valid: https://host:port)"),
|
||||
}
|
||||
}
|
||||
|
||||
return []string{}, []error{}
|
||||
},
|
||||
},
|
||||
mkProviderVirtualEnvironmentInsecure: {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "Whether to skip the TLS verification step",
|
||||
Default: false,
|
||||
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
|
||||
},
|
||||
},
|
||||
mkProviderVirtualEnvironmentPassword: {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
Description: "The password for the Proxmox Virtual Environment API",
|
||||
DefaultFunc: schema.MultiEnvDefaultFunc(
|
||||
[]string{"PROXMOX_VE_PASSWORD", "PM_VE_PASSWORD"},
|
||||
"",
|
||||
),
|
||||
ValidateFunc: func(v interface{}, k string) (warns []string, errs []error) {
|
||||
value := v.(string)
|
||||
|
||||
if value == "" {
|
||||
return []string{}, []error{
|
||||
errors.New("You must specify a password for the Proxmox Virtual Environment API"),
|
||||
}
|
||||
}
|
||||
|
||||
return []string{}, []error{}
|
||||
},
|
||||
},
|
||||
mkProviderVirtualEnvironmentUsername: {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
Description: "The username for the Proxmox Virtual Environment API",
|
||||
DefaultFunc: schema.MultiEnvDefaultFunc(
|
||||
[]string{"PROXMOX_VE_USERNAME", "PM_VE_USERNAME"},
|
||||
"",
|
||||
),
|
||||
ValidateFunc: func(v interface{}, k string) (warns []string, errs []error) {
|
||||
value := v.(string)
|
||||
|
||||
if value == "" {
|
||||
return []string{}, []error{
|
||||
errors.New("You must specify a username for the Proxmox Virtual Environment API (valid: username@realm)"),
|
||||
}
|
||||
}
|
||||
|
||||
return []string{}, []error{}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -113,7 +178,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||
|
||||
func (c *providerConfiguration) GetVEClient() (*proxmox.VirtualEnvironmentClient, error) {
|
||||
if c.veClient == nil {
|
||||
return nil, errors.New("You must specify the virtual environment details in the provider configuration to use this data source")
|
||||
return nil, errors.New("You must specify the virtual environment details in the provider configuration")
|
||||
}
|
||||
|
||||
return c.veClient, nil
|
||||
|
@ -37,16 +37,13 @@ func TestProviderSchema(t *testing.T) {
|
||||
|
||||
veSchema := testNestedSchemaExistence(t, s, mkProviderVirtualEnvironment)
|
||||
|
||||
testRequiredArguments(t, veSchema, []string{
|
||||
testOptionalArguments(t, veSchema, []string{
|
||||
mkProviderVirtualEnvironmentEndpoint,
|
||||
mkProviderVirtualEnvironmentInsecure,
|
||||
mkProviderVirtualEnvironmentPassword,
|
||||
mkProviderVirtualEnvironmentUsername,
|
||||
})
|
||||
|
||||
testOptionalArguments(t, veSchema, []string{
|
||||
mkProviderVirtualEnvironmentInsecure,
|
||||
})
|
||||
|
||||
testSchemaValueTypes(t, veSchema, []string{
|
||||
mkProviderVirtualEnvironmentEndpoint,
|
||||
mkProviderVirtualEnvironmentInsecure,
|
||||
|
Loading…
Reference in New Issue
Block a user