forked from Pryz/terraform-provider-ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider.go
60 lines (55 loc) · 1.79 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
package main
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Provider creates a new LDAP provider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"ldap_host": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("LDAP_HOST", nil),
Description: "The LDAP server to connect to.",
},
"ldap_port": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("LDAP_PORT", 389),
Description: "The LDAP protocol port (default: 389).",
},
"use_tls": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("LDAP_USE_TLS", true),
Description: "Use TLS to secure the connection (default: true).",
},
"bind_user": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("LDAP_BIND_USER", nil),
Description: "Bind user to be used for authenticating on the LDAP server.",
},
"bind_password": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("LDAP_BIND_PASSWORD", nil),
Description: "Password to authenticate the Bind user.",
},
},
ResourcesMap: map[string]*schema.Resource{
"ldap_object": resourceLDAPObject(),
},
ConfigureFunc: configureProvider,
}
}
func configureProvider(d *schema.ResourceData) (interface{}, error) {
return &Config{
LDAPHost: d.Get("ldap_host").(string),
LDAPPort: d.Get("ldap_port").(int),
UseTLS: d.Get("use_tls").(bool),
BindUser: d.Get("bind_user").(string),
BindPassword: d.Get("bind_password").(string),
}, nil
}