-
Notifications
You must be signed in to change notification settings - Fork 31
/
provider.go
75 lines (63 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
72
73
74
75
package ad
import (
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"domain": {
Type: schema.TypeString,
Required: true,
Description: "The Domain in which AD Server resides",
DefaultFunc: schema.EnvDefaultFunc("AD_DOMAIN", nil),
},
"ip": {
Type: schema.TypeString,
Optional: true,
Description: "The IP of the AD Server",
DefaultFunc: schema.EnvDefaultFunc("AD_IP", nil),
},
"url": {
Type: schema.TypeString,
Optional: true,
Description: "The LDAP URL of the AD Server",
DefaultFunc: schema.EnvDefaultFunc("AD_URL", nil),
},
"user": {
Type: schema.TypeString,
Required: true,
Description: "The user name of the AD Server",
DefaultFunc: schema.EnvDefaultFunc("AD_USER", nil),
},
"password": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
Description: "The user password of the AD Server",
DefaultFunc: schema.EnvDefaultFunc("AD_PASSWORD", nil),
},
},
ResourcesMap: map[string]*schema.Resource{
"ad_computer": resourceComputer(),
"ad_organizational_unit": resourceOU(),
"ad_computer_to_ou": resourceComputerToOU(),
"ad_group_to_ou": resourceGroupToOU(),
"ad_add_to_group": resourceAddToGroup(),
"ad_user": resourceUser(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Domain: d.Get("domain").(string),
IP: d.Get("ip").(string),
URL: d.Get("url").(string),
Username: d.Get("user").(string),
Password: d.Get("password").(string),
}
log.Printf("[DEBUG] Connecting to AD")
return config.Client()
}