github.com/renier/terraform@v0.7.8-0.20161024133817-eb8a9ef5471a/builtin/providers/scaleway/provider.go (about)

     1  package scaleway
     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  			"access_key": &schema.Schema{
    13  				Type:        schema.TypeString,
    14  				Required:    true,
    15  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ACCESS_KEY", nil),
    16  				Description: "The API key for Scaleway API operations.",
    17  			},
    18  			"organization": &schema.Schema{
    19  				Type:        schema.TypeString,
    20  				Required:    true,
    21  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ORGANIZATION", nil),
    22  				Description: "The Organization ID for Scaleway API operations.",
    23  			},
    24  			"region": &schema.Schema{
    25  				Type:        schema.TypeString,
    26  				Optional:    true,
    27  				DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_REGION", "par1"),
    28  				Description: "The Scaleway API region to use.",
    29  			},
    30  		},
    31  
    32  		ResourcesMap: map[string]*schema.Resource{
    33  			"scaleway_server":              resourceScalewayServer(),
    34  			"scaleway_ip":                  resourceScalewayIP(),
    35  			"scaleway_security_group":      resourceScalewaySecurityGroup(),
    36  			"scaleway_security_group_rule": resourceScalewaySecurityGroupRule(),
    37  			"scaleway_volume":              resourceScalewayVolume(),
    38  			"scaleway_volume_attachment":   resourceScalewayVolumeAttachment(),
    39  		},
    40  
    41  		DataSourcesMap: map[string]*schema.Resource{
    42  			"scaleway_bootscript": dataSourceScalewayBootscript(),
    43  			"scaleway_image":      dataSourceScalewayImage(),
    44  		},
    45  
    46  		ConfigureFunc: providerConfigure,
    47  	}
    48  }
    49  
    50  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    51  	config := Config{
    52  		Organization: d.Get("organization").(string),
    53  		APIKey:       d.Get("access_key").(string),
    54  		Region:       d.Get("region").(string),
    55  	}
    56  
    57  	return config.Client()
    58  }