Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/vsphere: restore vcenter_server as deprecated field #4145

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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