mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-10-05 02:01:04 +00:00
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package proxmox
|
|
|
|
import (
|
|
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
type providerConfiguration struct {
|
|
Client *pxapi.Client
|
|
}
|
|
|
|
func Provider() *schema.Provider {
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"pm_user": {
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
DefaultFunc: schema.EnvDefaultFunc("PM_USER", nil),
|
|
Description: "username, maywith with @pam",
|
|
},
|
|
"pm_password": {
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
DefaultFunc: schema.EnvDefaultFunc("PM_PASS", nil),
|
|
Description: "secret",
|
|
},
|
|
"pm_api_url": {
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
DefaultFunc: schema.EnvDefaultFunc("PM_API_URL", nil),
|
|
Description: "https://host.fqdn:8006/api2/json",
|
|
},
|
|
},
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
|
"proxmox_vm_qemu": resourceVmQemu(),
|
|
// TODO - storage_iso
|
|
// TODO - bridge
|
|
// TODO - vm_qemu_template
|
|
},
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
}
|
|
}
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
client, _ := pxapi.NewClient(d.Get("pm_api_url").(string), nil, nil)
|
|
err := client.Login(d.Get("pm_user").(string), d.Get("pm_password").(string))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &providerConfiguration{
|
|
Client: client,
|
|
}, nil
|
|
}
|