github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/builtin/providers/google/provider.go (about)

     1  package google
     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  			"account_file": &schema.Schema{
    13  				Type:        schema.TypeString,
    14  				Optional:    true,
    15  				DefaultFunc: schema.EnvDefaultFunc("GOOGLE_ACCOUNT_FILE", nil),
    16  			},
    17  
    18  			"project": &schema.Schema{
    19  				Type:        schema.TypeString,
    20  				Required:    true,
    21  				DefaultFunc: schema.EnvDefaultFunc("GOOGLE_PROJECT", nil),
    22  			},
    23  
    24  			"region": &schema.Schema{
    25  				Type:        schema.TypeString,
    26  				Required:    true,
    27  				DefaultFunc: schema.EnvDefaultFunc("GOOGLE_REGION", nil),
    28  			},
    29  		},
    30  
    31  		ResourcesMap: map[string]*schema.Resource{
    32  			"google_compute_address":           resourceComputeAddress(),
    33  			"google_compute_disk":              resourceComputeDisk(),
    34  			"google_compute_firewall":          resourceComputeFirewall(),
    35  			"google_compute_forwarding_rule":   resourceComputeForwardingRule(),
    36  			"google_compute_http_health_check": resourceComputeHttpHealthCheck(),
    37  			"google_compute_instance":          resourceComputeInstance(),
    38  			"google_compute_instance_template": resourceComputeInstanceTemplate(),
    39  			"google_compute_network":           resourceComputeNetwork(),
    40  			"google_compute_route":             resourceComputeRoute(),
    41  			"google_compute_target_pool":       resourceComputeTargetPool(),
    42  		},
    43  
    44  		ConfigureFunc: providerConfigure,
    45  	}
    46  }
    47  
    48  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    49  	config := Config{
    50  		AccountFile: d.Get("account_file").(string),
    51  		Project:     d.Get("project").(string),
    52  		Region:      d.Get("region").(string),
    53  	}
    54  
    55  	if err := config.loadAndValidate(); err != nil {
    56  		return nil, err
    57  	}
    58  
    59  	return &config, nil
    60  }