Skip to content

Commit

Permalink
provider/vsphere: restore vcenter_server as deprecated field
Browse files Browse the repository at this point in the history
As promised in my comment in #3718, this preserves backwards
compatibility while warning users of the new proper name for the field.
  • Loading branch information
phinze committed Dec 10, 2015
1 parent b11966b commit cfea7c8
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions builtin/providers/vsphere/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vsphere

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
Expand All @@ -25,21 +27,26 @@ func Provider() terraform.ResourceProvider {

"vsphere_server": &schema.Schema{
Type: schema.TypeString,
Required: true,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_SERVER", nil),
Description: "The vSphere Server name for vSphere API operations.",
},

"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.",
},
"vcenter_server": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_VCENTER", nil),
Deprecated: "This field has been renamed to vsphere_server.",
},
},

ResourcesMap: map[string]*schema.Resource{
"vsphere_folder": resourceVSphereFolder(),
"vsphere_folder": resourceVSphereFolder(),
"vsphere_virtual_machine": resourceVSphereVirtualMachine(),
},

Expand All @@ -48,11 +55,25 @@ func Provider() terraform.ResourceProvider {
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
// 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.")
}

config := Config{
User: d.Get("user").(string),
Password: d.Get("password").(string),
VSphereServer: d.Get("vsphere_server").(string),
InsecureFlag: d.Get("allow_unverified_ssl").(bool),
VSphereServer: server,
}

return config.Client()
Expand Down

0 comments on commit cfea7c8

Please sign in to comment.