2015-10-06 05:53:07 +02:00
|
|
|
package vsphere
|
|
|
|
|
|
|
|
import (
|
2015-12-02 21:08:14 +01:00
|
|
|
"fmt"
|
|
|
|
|
2015-10-06 05:53:07 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"user": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_USER", nil),
|
|
|
|
Description: "The user name for vSphere API operations.",
|
|
|
|
},
|
|
|
|
|
|
|
|
"password": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_PASSWORD", nil),
|
|
|
|
Description: "The user password for vSphere API operations.",
|
|
|
|
},
|
|
|
|
|
2015-11-01 15:07:23 +01:00
|
|
|
"vsphere_server": &schema.Schema{
|
2015-10-06 05:53:07 +02:00
|
|
|
Type: schema.TypeString,
|
2015-12-02 21:08:14 +01:00
|
|
|
Optional: true,
|
2015-11-01 15:07:23 +01:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_SERVER", nil),
|
|
|
|
Description: "The vSphere Server name for vSphere API operations.",
|
2015-10-06 05:53:07 +02:00
|
|
|
},
|
2015-11-15 04:24:28 +01:00
|
|
|
"allow_unverified_ssl": &schema.Schema{
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_ALLOW_UNVERIFIED_SSL", false),
|
|
|
|
Description: "If set, VMware vSphere client will permit unverifiable SSL certificates.",
|
|
|
|
},
|
2015-12-02 21:08:14 +01:00
|
|
|
"vcenter_server": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_VCENTER", nil),
|
|
|
|
Deprecated: "This field has been renamed to vsphere_server.",
|
|
|
|
},
|
2015-10-06 05:53:07 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2016-05-02 22:25:35 +02:00
|
|
|
"vsphere_file": resourceVSphereFile(),
|
2015-12-02 21:08:14 +01:00
|
|
|
"vsphere_folder": resourceVSphereFolder(),
|
2016-05-25 12:21:16 +02:00
|
|
|
"vsphere_virtual_disk": resourceVSphereVirtualDisk(),
|
2015-10-06 05:53:07 +02:00
|
|
|
"vsphere_virtual_machine": resourceVSphereVirtualMachine(),
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
2015-12-02 21:08:14 +01:00
|
|
|
// Handle backcompat support for vcenter_server; once that is removed,
|
|
|
|
// vsphere_server can just become a Required field that is referenced inline
|
|
|
|
// in Config below.
|
|
|
|
server := d.Get("vsphere_server").(string)
|
|
|
|
|
|
|
|
if server == "" {
|
|
|
|
server = d.Get("vcenter_server").(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
if server == "" {
|
|
|
|
return nil, fmt.Errorf(
|
|
|
|
"One of vsphere_server or [deprecated] vcenter_server must be provided.")
|
|
|
|
}
|
|
|
|
|
2015-10-06 05:53:07 +02:00
|
|
|
config := Config{
|
|
|
|
User: d.Get("user").(string),
|
|
|
|
Password: d.Get("password").(string),
|
2015-11-15 04:24:28 +01:00
|
|
|
InsecureFlag: d.Get("allow_unverified_ssl").(bool),
|
2015-12-02 21:08:14 +01:00
|
|
|
VSphereServer: server,
|
2015-10-06 05:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return config.Client()
|
|
|
|
}
|