-
Notifications
You must be signed in to change notification settings - Fork 5
/
provider.go
58 lines (52 loc) · 1.6 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
package main
import (
"log"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
//Provider definition for kea-dhcpd
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"kea_server_address": {
Type: schema.TypeString,
Required: true,
Description: "IP or FQDN of host which serve DHCP daemon",
},
"kea_server_username": {
Type: schema.TypeString,
Required: true,
Description: "omapi key name defined in dhcpd.conf",
},
"kea_server_password": {
Type: schema.TypeString,
Required: true,
Description: "Value of the key defined in dhcpd.conf",
},
"kea_server_configfile": {
Type: schema.TypeString,
Optional: true,
Description: "Value of the key defined in dhcpd.conf",
},
},
ResourcesMap: map[string]*schema.Resource{
"kea-dhcp4_host_lease": hostLease(),
},
ConfigureFunc: configureProvider,
}
}
func configureProvider(d *schema.ResourceData) (interface{}, error) {
config := Config{
Server: d.Get("kea_server_address").(string),
Username: d.Get("kea_server_username").(string),
Password: d.Get("kea_server_password").(string),
Configfile: d.Get("kea_server_configfile").(string),
}
log.Printf("[DEBUG] Configuring Server for kea-dhcpd: '%s': %v", config.Server, d)
log.Printf("[DEBUG] Configuring Username for kea-dhcpd: '%s': %v", config.Username, d)
log.Printf("[DEBUG] Configuring config file for kea-dhcpd: '%s': %v", config.Configfile, d)
client, err := config.Client()
if err != nil {
return nil, err
}
return client, nil
}