github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/builtin/providers/vsphere/provider.go (about) 1 package vsphere 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/terraform/helper/schema" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 // Provider returns a terraform.ResourceProvider. 11 func Provider() terraform.ResourceProvider { 12 return &schema.Provider{ 13 Schema: map[string]*schema.Schema{ 14 "user": &schema.Schema{ 15 Type: schema.TypeString, 16 Required: true, 17 DefaultFunc: schema.EnvDefaultFunc("VSPHERE_USER", nil), 18 Description: "The user name for vSphere API operations.", 19 }, 20 21 "password": &schema.Schema{ 22 Type: schema.TypeString, 23 Required: true, 24 DefaultFunc: schema.EnvDefaultFunc("VSPHERE_PASSWORD", nil), 25 Description: "The user password for vSphere API operations.", 26 }, 27 28 "vsphere_server": &schema.Schema{ 29 Type: schema.TypeString, 30 Optional: true, 31 DefaultFunc: schema.EnvDefaultFunc("VSPHERE_SERVER", nil), 32 Description: "The vSphere Server name for vSphere API operations.", 33 }, 34 "allow_unverified_ssl": &schema.Schema{ 35 Type: schema.TypeBool, 36 Optional: true, 37 DefaultFunc: schema.EnvDefaultFunc("VSPHERE_ALLOW_UNVERIFIED_SSL", false), 38 Description: "If set, VMware vSphere client will permit unverifiable SSL certificates.", 39 }, 40 "vcenter_server": &schema.Schema{ 41 Type: schema.TypeString, 42 Optional: true, 43 DefaultFunc: schema.EnvDefaultFunc("VSPHERE_VCENTER", nil), 44 Deprecated: "This field has been renamed to vsphere_server.", 45 }, 46 }, 47 48 ResourcesMap: map[string]*schema.Resource{ 49 "vsphere_folder": resourceVSphereFolder(), 50 "vsphere_virtual_machine": resourceVSphereVirtualMachine(), 51 }, 52 53 ConfigureFunc: providerConfigure, 54 } 55 } 56 57 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 58 // Handle backcompat support for vcenter_server; once that is removed, 59 // vsphere_server can just become a Required field that is referenced inline 60 // in Config below. 61 server := d.Get("vsphere_server").(string) 62 63 if server == "" { 64 server = d.Get("vcenter_server").(string) 65 } 66 67 if server == "" { 68 return nil, fmt.Errorf( 69 "One of vsphere_server or [deprecated] vcenter_server must be provided.") 70 } 71 72 config := Config{ 73 User: d.Get("user").(string), 74 Password: d.Get("password").(string), 75 InsecureFlag: d.Get("allow_unverified_ssl").(bool), 76 VSphereServer: server, 77 } 78 79 return config.Client() 80 }