github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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  				Optional:    true,
    16  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ACCESS_KEY", nil),
    17  				Deprecated:  "Use `token` instead.",
    18  				Description: "The API key for Scaleway API operations.",
    19  			},
    20  			"token": &schema.Schema{
    21  				Type:     schema.TypeString,
    22  				Required: true,
    23  				DefaultFunc: schema.MultiEnvDefaultFunc([]string{
    24  					"SCALEWAY_TOKEN",
    25  					"SCALEWAY_ACCESS_KEY",
    26  				}, nil),
    27  				Description: "The API key for Scaleway API operations.",
    28  			},
    29  			"organization": &schema.Schema{
    30  				Type:        schema.TypeString,
    31  				Required:    true,
    32  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ORGANIZATION", nil),
    33  				Description: "The Organization ID (a.k.a. 'access key') for Scaleway API operations.",
    34  			},
    35  			"region": &schema.Schema{
    36  				Type:        schema.TypeString,
    37  				Optional:    true,
    38  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_REGION", "par1"),
    39  				Description: "The Scaleway API region to use.",
    40  			},
    41  		},
    42  
    43  		ResourcesMap: map[string]*schema.Resource{
    44  			"scaleway_server":              resourceScalewayServer(),
    45  			"scaleway_ip":                  resourceScalewayIP(),
    46  			"scaleway_security_group":      resourceScalewaySecurityGroup(),
    47  			"scaleway_security_group_rule": resourceScalewaySecurityGroupRule(),
    48  			"scaleway_volume":              resourceScalewayVolume(),
    49  			"scaleway_volume_attachment":   resourceScalewayVolumeAttachment(),
    50  		},
    51  
    52  		DataSourcesMap: map[string]*schema.Resource{
    53  			"scaleway_bootscript": dataSourceScalewayBootscript(),
    54  			"scaleway_image":      dataSourceScalewayImage(),
    55  		},
    56  
    57  		ConfigureFunc: providerConfigure,
    58  	}
    59  }
    60  
    61  var scalewayMutexKV = mutexkv.NewMutexKV()
    62  
    63  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    64  	apiKey := ""
    65  	if v, ok := d.Get("token").(string); ok {
    66  		apiKey = v
    67  	} else {
    68  		if v, ok := d.Get("access_key").(string); ok {
    69  			apiKey = v
    70  		}
    71  	}
    72  
    73  	config := Config{
    74  		Organization: d.Get("organization").(string),
    75  		APIKey:       apiKey,
    76  		Region:       d.Get("region").(string),
    77  	}
    78  
    79  	return config.Client()
    80  }