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

     1  package vcd
     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("VCD_USER", nil),
    16  				Description: "The user name for vcd API operations.",
    17  			},
    18  
    19  			"password": &schema.Schema{
    20  				Type:        schema.TypeString,
    21  				Required:    true,
    22  				DefaultFunc: schema.EnvDefaultFunc("VCD_PASSWORD", nil),
    23  				Description: "The user password for vcd API operations.",
    24  			},
    25  
    26  			"org": &schema.Schema{
    27  				Type:        schema.TypeString,
    28  				Required:    true,
    29  				DefaultFunc: schema.EnvDefaultFunc("VCD_ORG", nil),
    30  				Description: "The vcd org for API operations",
    31  			},
    32  
    33  			"url": &schema.Schema{
    34  				Type:        schema.TypeString,
    35  				Required:    true,
    36  				DefaultFunc: schema.EnvDefaultFunc("VCD_URL", nil),
    37  				Description: "The vcd url for vcd API operations.",
    38  			},
    39  
    40  			"vdc": &schema.Schema{
    41  				Type:        schema.TypeString,
    42  				Optional:    true,
    43  				DefaultFunc: schema.EnvDefaultFunc("VCD_VDC", ""),
    44  				Description: "The name of the VDC to run operations on",
    45  			},
    46  
    47  			"maxRetryTimeout": &schema.Schema{
    48  				Type:        schema.TypeInt,
    49  				Optional:    true,
    50  				DefaultFunc: schema.EnvDefaultFunc("VCD_MAX_RETRY_TIMEOUT", 60),
    51  				Description: "Max num seconds to wait for successful response when operating on resources within vCloud (defaults to 60)",
    52  			},
    53  		},
    54  
    55  		ResourcesMap: map[string]*schema.Resource{
    56  			"vcd_network":        resourceVcdNetwork(),
    57  			"vcd_vapp":           resourceVcdVApp(),
    58  			"vcd_firewall_rules": resourceVcdFirewallRules(),
    59  			"vcd_dnat":           resourceVcdDNAT(),
    60  			"vcd_snat":           resourceVcdSNAT(),
    61  		},
    62  
    63  		ConfigureFunc: providerConfigure,
    64  	}
    65  }
    66  
    67  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    68  	config := Config{
    69  		User:         d.Get("user").(string),
    70  		Password:     d.Get("password").(string),
    71  		Org:          d.Get("org").(string),
    72  		Href:         d.Get("url").(string),
    73  		VDC:          d.Get("vdc").(string),
    74  		MaxRetryTimeout: d.Get("maxRetryTimeout").(int),
    75  	}
    76  
    77  	return config.Client()
    78  }