2017-01-18 15:43:09 +01:00
|
|
|
package profitbricks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2017-02-02 14:26:14 +01:00
|
|
|
"github.com/profitbricks/profitbricks-sdk-go"
|
2017-01-18 15:43:09 +01:00
|
|
|
)
|
|
|
|
|
2017-03-25 21:43:41 +01:00
|
|
|
// Provider returns a schema.Provider for ProfitBricks.
|
2017-01-18 15:43:09 +01:00
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"username": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_USERNAME", nil),
|
2017-03-25 21:43:41 +01:00
|
|
|
Description: "ProfitBricks username for API operations.",
|
2017-01-18 15:43:09 +01:00
|
|
|
},
|
|
|
|
"password": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_PASSWORD", nil),
|
2017-03-25 21:43:41 +01:00
|
|
|
Description: "ProfitBricks password for API operations.",
|
2017-01-18 15:43:09 +01:00
|
|
|
},
|
2017-02-02 14:26:14 +01:00
|
|
|
"endpoint": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_API_URL", profitbricks.Endpoint),
|
2017-03-25 21:43:41 +01:00
|
|
|
Description: "ProfitBricks REST API URL.",
|
2017-02-02 14:26:14 +01:00
|
|
|
},
|
2017-01-18 15:43:09 +01:00
|
|
|
"retries": {
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Default: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
|
|
|
"profitbricks_datacenter": resourceProfitBricksDatacenter(),
|
|
|
|
"profitbricks_ipblock": resourceProfitBricksIPBlock(),
|
|
|
|
"profitbricks_firewall": resourceProfitBricksFirewall(),
|
|
|
|
"profitbricks_lan": resourceProfitBricksLan(),
|
|
|
|
"profitbricks_loadbalancer": resourceProfitBricksLoadbalancer(),
|
|
|
|
"profitbricks_nic": resourceProfitBricksNic(),
|
|
|
|
"profitbricks_server": resourceProfitBricksServer(),
|
|
|
|
"profitbricks_volume": resourceProfitBricksVolume(),
|
|
|
|
},
|
2017-02-02 14:26:14 +01:00
|
|
|
DataSourcesMap: map[string]*schema.Resource{
|
|
|
|
"profitbricks_datacenter": dataSourceDataCenter(),
|
|
|
|
"profitbricks_location": dataSourceLocation(),
|
|
|
|
"profitbricks_image": dataSourceImage(),
|
|
|
|
},
|
2017-01-18 15:43:09 +01:00
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
|
|
|
|
if _, ok := d.GetOk("username"); !ok {
|
|
|
|
return nil, fmt.Errorf("ProfitBricks username has not been provided.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := d.GetOk("password"); !ok {
|
|
|
|
return nil, fmt.Errorf("ProfitBricks password has not been provided.")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := Config{
|
|
|
|
Username: d.Get("username").(string),
|
|
|
|
Password: d.Get("password").(string),
|
2017-02-02 14:26:14 +01:00
|
|
|
Endpoint: d.Get("endpoint").(string),
|
2017-01-18 15:43:09 +01:00
|
|
|
Retries: d.Get("retries").(int),
|
|
|
|
}
|
|
|
|
|
|
|
|
return config.Client()
|
|
|
|
}
|