github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/scaleway/provider.go (about)

     1  package scaleway
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/helper/mutexkv"
     5  	"github.com/hashicorp/terraform/helper/schema"
     6  	"github.com/hashicorp/terraform/terraform"
     7  )
     8  
     9  // Provider returns a terraform.ResourceProvider.
    10  func Provider() terraform.ResourceProvider {
    11  	return &schema.Provider{
    12  		Schema: map[string]*schema.Schema{
    13  			"access_key": &schema.Schema{
    14  				Type:        schema.TypeString,
    15  				Required:    true,
    16  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ACCESS_KEY", nil),
    17  				Description: "The API key for Scaleway API operations.",
    18  			},
    19  			"organization": &schema.Schema{
    20  				Type:        schema.TypeString,
    21  				Required:    true,
    22  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ORGANIZATION", nil),
    23  				Description: "The Organization ID for Scaleway API operations.",
    24  			},
    25  			"region": &schema.Schema{
    26  				Type:        schema.TypeString,
    27  				Optional:    true,
    28  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_REGION", "par1"),
    29  				Description: "The Scaleway API region to use.",
    30  			},
    31  		},
    32  
    33  		ResourcesMap: map[string]*schema.Resource{
    34  			"scaleway_server":              resourceScalewayServer(),
    35  			"scaleway_ip":                  resourceScalewayIP(),
    36  			"scaleway_security_group":      resourceScalewaySecurityGroup(),
    37  			"scaleway_security_group_rule": resourceScalewaySecurityGroupRule(),
    38  			"scaleway_volume":              resourceScalewayVolume(),
    39  			"scaleway_volume_attachment":   resourceScalewayVolumeAttachment(),
    40  		},
    41  
    42  		DataSourcesMap: map[string]*schema.Resource{
    43  			"scaleway_bootscript": dataSourceScalewayBootscript(),
    44  			"scaleway_image":      dataSourceScalewayImage(),
    45  		},
    46  
    47  		ConfigureFunc: providerConfigure,
    48  	}
    49  }
    50  
    51  var scalewayMutexKV = mutexkv.NewMutexKV()
    52  
    53  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    54  	config := Config{
    55  		Organization: d.Get("organization").(string),
    56  		APIKey:       d.Get("access_key").(string),
    57  		Region:       d.Get("region").(string),
    58  	}
    59  
    60  	return config.Client()
    61  }