github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/vsphere/provider.go (about)

     1  package vsphere
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/helper/schema"
     5  	"github.com/hashicorp/terraform/terraform"
     6  )
     7  
     8  // Provider returns a terraform.ResourceProvider.
     9  func Provider() terraform.ResourceProvider {
    10  	return &schema.Provider{
    11  		Schema: map[string]*schema.Schema{
    12  			"user": &schema.Schema{
    13  				Type:        schema.TypeString,
    14  				Required:    true,
    15  				DefaultFunc: schema.EnvDefaultFunc("VSPHERE_USER", nil),
    16  				Description: "The user name for vSphere API operations.",
    17  			},
    18  
    19  			"password": &schema.Schema{
    20  				Type:        schema.TypeString,
    21  				Required:    true,
    22  				DefaultFunc: schema.EnvDefaultFunc("VSPHERE_PASSWORD", nil),
    23  				Description: "The user password for vSphere API operations.",
    24  			},
    25  
    26  			"vsphere_server": &schema.Schema{
    27  				Type:        schema.TypeString,
    28  				Required:    true,
    29  				DefaultFunc: schema.EnvDefaultFunc("VSPHERE_SERVER", nil),
    30  				Description: "The vSphere Server name for vSphere API operations.",
    31  			},
    32  		},
    33  
    34  		ResourcesMap: map[string]*schema.Resource{
    35  			"vsphere_virtual_machine": resourceVSphereVirtualMachine(),
    36  		},
    37  
    38  		ConfigureFunc: providerConfigure,
    39  	}
    40  }
    41  
    42  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    43  	config := Config{
    44  		User:          d.Get("user").(string),
    45  		Password:      d.Get("password").(string),
    46  		VSphereServer: d.Get("vsphere_server").(string),
    47  	}
    48  
    49  	return config.Client()
    50  }