-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathprovider.go
71 lines (64 loc) · 1.88 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
package aviatrix
import (
"os"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Provider returns a schema.Provider for Aviatrix.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"controller_ip": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("AVIATRIX_CONTROLLER_IP"),
},
"username": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("AVIATRIX_USERNAME"),
},
"password": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("AVIATRIX_PASSWORD"),
},
},
ResourcesMap: map[string]*schema.Resource{
"aviatrix_account": resourceAccount(),
"aviatrix_admin_email" : resourceAdminEmail(),
"aviatrix_customer_id" : resourceCustomerID(),
"aviatrix_gateway": resourceAviatrixGateway(),
"aviatrix_tunnel" : resourceTunnel(),
"aviatrix_transpeer" : resourceTranspeer(),
},
DataSourcesMap: map[string]*schema.Resource{
"aviatrix_caller_identity": dataSourceAviatrixCallerIdentity(),
"aviatrix_account": dataSourceAviatrixAccount(),
"aviatrix_gateway": dataSourceAviatrixGateway(),
},
ConfigureFunc: aviatrixConfigure,
}
}
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
return func() (interface{}, error) {
if v := os.Getenv(k); v != "" {
return v, nil
}
return nil, nil
}
}
func envDefaultFuncAllowMissing(k string) schema.SchemaDefaultFunc {
return func() (interface{}, error) {
v := os.Getenv(k)
return v, nil
}
}
func aviatrixConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
ControllerIP: d.Get("controller_ip").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
}
return config.Client()
}