Merge pull request #4145 from hashicorp/phinze/vcenter-server-backcompat

provider/vsphere: restore vcenter_server as deprecated field
This commit is contained in:
Paul Hinze 2015-12-10 12:29:15 -06:00
commit 38d9b29026
1 changed files with 25 additions and 4 deletions

View File

@ -1,6 +1,8 @@
package vsphere package vsphere
import ( import (
"fmt"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -25,21 +27,26 @@ func Provider() terraform.ResourceProvider {
"vsphere_server": &schema.Schema{ "vsphere_server": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_SERVER", nil), DefaultFunc: schema.EnvDefaultFunc("VSPHERE_SERVER", nil),
Description: "The vSphere Server name for vSphere API operations.", Description: "The vSphere Server name for vSphere API operations.",
}, },
"allow_unverified_ssl": &schema.Schema{ "allow_unverified_ssl": &schema.Schema{
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_ALLOW_UNVERIFIED_SSL", false), DefaultFunc: schema.EnvDefaultFunc("VSPHERE_ALLOW_UNVERIFIED_SSL", false),
Description: "If set, VMware vSphere client will permit unverifiable SSL certificates.", 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{ ResourcesMap: map[string]*schema.Resource{
"vsphere_folder": resourceVSphereFolder(), "vsphere_folder": resourceVSphereFolder(),
"vsphere_virtual_machine": resourceVSphereVirtualMachine(), "vsphere_virtual_machine": resourceVSphereVirtualMachine(),
}, },
@ -48,11 +55,25 @@ func Provider() terraform.ResourceProvider {
} }
func providerConfigure(d *schema.ResourceData) (interface{}, error) { 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{ config := Config{
User: d.Get("user").(string), User: d.Get("user").(string),
Password: d.Get("password").(string), Password: d.Get("password").(string),
VSphereServer: d.Get("vsphere_server").(string),
InsecureFlag: d.Get("allow_unverified_ssl").(bool), InsecureFlag: d.Get("allow_unverified_ssl").(bool),
VSphereServer: server,
} }
return config.Client() return config.Client()