forked from Kamatera/terraform-provider-kamatera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider.go
55 lines (50 loc) · 1.46 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
package main
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func Provider() *schema.Provider {
return &schema.Provider{
ConfigureFunc: ConfigureProvider,
Schema: map[string]*schema.Schema{
"api_client_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("KAMATERA_API_CLIENT_ID", nil),
Description: "Kamatera API Client ID",
},
"api_secret": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("KAMATERA_API_SECRET", nil),
Description: "Kamatera API Secret",
},
"api_url": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KAMATERA_API_URL", "https://cloudcli.cloudwm.com"),
Description: "Kamatera API Url",
},
},
DataSourcesMap: map[string]*schema.Resource{
"kamatera_datacenter": dataSourceDatacenter(),
"kamatera_image": dataSourceImage(),
"kamatera_server_options": dataSourceServerOptions(),
},
ResourcesMap: map[string]*schema.Resource{
"kamatera_server": resourceServer(),
},
}
}
type ProviderConfiguration struct {
ApiUrl string
ApiClientID string
ApiSecret string
}
func ConfigureProvider(d *schema.ResourceData) (interface{}, error) {
config := ProviderConfiguration{
ApiUrl: d.Get("api_url").(string),
ApiClientID: d.Get("api_client_id").(string),
ApiSecret: d.Get("api_secret").(string),
}
return &config, nil
}