forked from hashicorp/terraform
/
provider.go
executable file
·70 lines (61 loc) · 1.94 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
package spotinst
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"email": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SPOTINST_EMAIL", ""),
Description: "Spotinst Email",
},
"password": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SPOTINST_PASSWORD", ""),
Description: "Spotinst Password",
},
"client_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SPOTINST_CLIENT_ID", ""),
Description: "Spotinst OAuth Client ID",
},
"client_secret": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SPOTINST_CLIENT_SECRET", ""),
Description: "Spotinst OAuth Client Secret",
},
"token": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SPOTINST_TOKEN", ""),
Description: "Spotinst Personal API Access Token",
},
},
ResourcesMap: map[string]*schema.Resource{
"spotinst_aws_group": resourceSpotinstAwsGroup(),
"spotinst_subscription": resourceSpotinstSubscription(),
"spotinst_healthcheck": resourceSpotinstHealthCheck(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Email: d.Get("email").(string),
Password: d.Get("password").(string),
ClientID: d.Get("client_id").(string),
ClientSecret: d.Get("client_secret").(string),
Token: d.Get("token").(string),
}
if err := config.Validate(); err != nil {
return nil, err
}
return config.Client()
}