github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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 "client_debug": &schema.Schema{ 47 Type: schema.TypeBool, 48 Optional: true, 49 DefaultFunc: schema.EnvDefaultFunc("VSPHERE_CLIENT_DEBUG", false), 50 Description: "govomomi debug", 51 }, 52 "client_debug_path_run": &schema.Schema{ 53 Type: schema.TypeString, 54 Optional: true, 55 DefaultFunc: schema.EnvDefaultFunc("VSPHERE_CLIENT_DEBUG_PATH_RUN", ""), 56 Description: "govomomi debug path for a single run", 57 }, 58 "client_debug_path": &schema.Schema{ 59 Type: schema.TypeString, 60 Optional: true, 61 DefaultFunc: schema.EnvDefaultFunc("VSPHERE_CLIENT_DEBUG_PATH", ""), 62 Description: "govomomi debug path for debug", 63 }, 64 }, 65 66 ResourcesMap: map[string]*schema.Resource{ 67 "vsphere_file": resourceVSphereFile(), 68 "vsphere_folder": resourceVSphereFolder(), 69 "vsphere_virtual_disk": resourceVSphereVirtualDisk(), 70 "vsphere_virtual_machine": resourceVSphereVirtualMachine(), 71 }, 72 73 ConfigureFunc: providerConfigure, 74 } 75 } 76 77 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 78 // Handle backcompat support for vcenter_server; once that is removed, 79 // vsphere_server can just become a Required field that is referenced inline 80 // in Config below. 81 server := d.Get("vsphere_server").(string) 82 83 if server == "" { 84 server = d.Get("vcenter_server").(string) 85 } 86 87 if server == "" { 88 return nil, fmt.Errorf( 89 "One of vsphere_server or [deprecated] vcenter_server must be provided.") 90 } 91 92 config := Config{ 93 User: d.Get("user").(string), 94 Password: d.Get("password").(string), 95 InsecureFlag: d.Get("allow_unverified_ssl").(bool), 96 VSphereServer: server, 97 Debug: d.Get("client_debug").(bool), 98 DebugPathRun: d.Get("client_debug_path_run").(string), 99 DebugPath: d.Get("client_debug_path").(string), 100 } 101 102 return config.Client() 103 }