forked from hashicorp/terraform
/
provider.go
76 lines (68 loc) · 2.34 KB
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package profitbricks
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/profitbricks/profitbricks-sdk-go"
)
// Provider returns a schema.Provider for DigitalOcean.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_USERNAME", nil),
Description: "Profitbricks username for API operations.",
},
"password": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_PASSWORD", nil),
Description: "Profitbricks password for API operations.",
},
"endpoint": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_API_URL", profitbricks.Endpoint),
Description: "Profitbricks REST API URL.",
},
"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(),
},
DataSourcesMap: map[string]*schema.Resource{
"profitbricks_datacenter": dataSourceDataCenter(),
"profitbricks_location": dataSourceLocation(),
"profitbricks_image": dataSourceImage(),
},
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),
Endpoint: d.Get("endpoint").(string),
Retries: d.Get("retries").(int),
}
return config.Client()
}