-
Notifications
You must be signed in to change notification settings - Fork 7
/
provider.go
84 lines (75 loc) · 2.13 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
76
77
78
79
80
81
82
83
84
package vault
import (
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/mapstructure"
)
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"address": &schema.Schema{
Type: schema.TypeString,
Description: "URL to the Vault server",
Required: true,
},
"user_id": &schema.Schema{
Type: schema.TypeString,
Description: "User ID for app-id authentication",
Optional: true,
Default: "",
},
"app_id": &schema.Schema{
Type: schema.TypeString,
Description: "App ID for app-id authentication",
Optional: true,
Default: "",
},
"user": &schema.Schema{
Type: schema.TypeString,
Description: "Username for userpass authentication",
Optional: true,
Default: "",
},
"pass": &schema.Schema{
Type: schema.TypeString,
Description: "Password for userpass authentication",
Optional: true,
Default: "",
},
"ldapuser": &schema.Schema{
Type: schema.TypeString,
Description: "Username for LDAP authentication",
Optional: true,
Default: "",
},
"ldappass": &schema.Schema{
Type: schema.TypeString,
Description: "Password for LDAP authentication",
Optional: true,
Default: "",
},
"token": &schema.Schema{
Type: schema.TypeString,
Description: "Token for direct authentication",
Optional: true,
Default: "",
},
},
ResourcesMap: map[string]*schema.Resource{
"vault_secret": resourceVaultSecret(),
},
ConfigureFunc: providerConfigure,
}
}
// Perform the initial configuration and authentication for the Vault client
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
log.Printf("[INFO] Configuring Vault provider")
// Copy existing ResourceData set into the vaultConfig struct
var config vaultConfig
configRaw := d.Get("").(map[string]interface{})
if err := mapstructure.Decode(configRaw, &config); err != nil {
return nil, err
}
return config.Client()
}