forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
63 lines (56 loc) · 1.44 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
package dme
import (
"os"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Provider provides a Provider...
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"akey": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("DME_AKEY"),
Description: "A DNSMadeEasy API Key.",
},
"skey": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("DME_SKEY"),
Description: "The Secret Key for API operations.",
},
"usesandbox": &schema.Schema{
Type: schema.TypeBool,
Required: true,
DefaultFunc: envDefaultFunc("DME_USESANDBOX"),
Description: "If true, use the DME Sandbox.",
},
},
ResourcesMap: map[string]*schema.Resource{
"dme_record": resourceDMERecord(),
},
ConfigureFunc: providerConfigure,
}
}
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
return func() (interface{}, error) {
if v := os.Getenv(k); v != "" {
if v == "true" {
return true, nil
} else if v == "false" {
return false, nil
}
return v, nil
}
return nil, nil
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
AKey: d.Get("akey").(string),
SKey: d.Get("skey").(string),
UseSandbox: d.Get("usesandbox").(bool),
}
return config.Client()
}