github.com/sarguru/terraform@v0.6.17-0.20160525232901-8fcdfd7e3dc9/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_file": resourceVSphereFile(), 50 "vsphere_folder": resourceVSphereFolder(), 51 "vsphere_virtual_disk": resourceVSphereVirtualDisk(), 52 "vsphere_virtual_machine": resourceVSphereVirtualMachine(), 53 }, 54 55 ConfigureFunc: providerConfigure, 56 } 57 } 58 59 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 60 // Handle backcompat support for vcenter_server; once that is removed, 61 // vsphere_server can just become a Required field that is referenced inline 62 // in Config below. 63 server := d.Get("vsphere_server").(string) 64 65 if server == "" { 66 server = d.Get("vcenter_server").(string) 67 } 68 69 if server == "" { 70 return nil, fmt.Errorf( 71 "One of vsphere_server or [deprecated] vcenter_server must be provided.") 72 } 73 74 config := Config{ 75 User: d.Get("user").(string), 76 Password: d.Get("password").(string), 77 InsecureFlag: d.Get("allow_unverified_ssl").(bool), 78 VSphereServer: server, 79 } 80 81 return config.Client() 82 }