-
Notifications
You must be signed in to change notification settings - Fork 3
/
provider.go
90 lines (82 loc) · 2.25 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
85
86
87
88
89
90
package main
import (
"log"
"strings"
"github.com/DelineaXPM/dsv-sdk-go/v2/auth"
"github.com/DelineaXPM/dsv-sdk-go/v2/vault"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func providerConfig(d *schema.ResourceData) (interface{}, error) {
c := vault.Configuration{
Tenant: d.Get("tenant").(string),
Credentials: vault.ClientCredential{
ClientID: d.Get("client_id").(string),
ClientSecret: d.Get("client_secret").(string),
},
}
c.Provider = auth.CLIENT
if prvd, exists := d.GetOk("auth_provider"); exists {
switch strings.ToLower(prvd.(string)) {
case "aws":
c.Provider = auth.AWS
}
}
log.Printf("[DEBUG] auth provider is set to %+v", c.Provider)
log.Printf("[DEBUG] tenant is set to %s", c.Tenant)
if tld, ok := d.GetOk("tld"); ok {
c.TLD = tld.(string)
log.Printf("[DEBUG] tld is set to %s", c.TLD)
}
if ut, ok := d.GetOk("url_template"); ok {
c.URLTemplate = ut.(string)
log.Printf("[DEBUG] url_template is set to %s", c.URLTemplate)
}
return c, nil
}
// Provider is a Terraform DataSource
func Provider() *schema.Provider {
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{
"dsv_client": dataSourceClient(),
"dsv_role": dataSourceRole(),
"dsv_secret": dataSourceSecret(),
},
ResourcesMap: map[string]*schema.Resource{
"dsv_client": resourceClient(),
},
Schema: map[string]*schema.Schema{
"tenant": {
Type: schema.TypeString,
Required: true,
Description: "The DevOps Secrets Vault tenant",
},
"client_id": {
Type: schema.TypeString,
Optional: true,
Description: "The DevOps Secrets Vault client_id",
},
"client_secret": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Description: "The DevOps Secrets Vault client_secret",
},
"auth_provider": {
Type: schema.TypeString,
Optional: true,
Description: "The DevOps Secrets Vault auth_provider",
},
"tld": {
Type: schema.TypeString,
Optional: true,
Description: "The DSV tenant top-level domain",
},
"url_template": {
Type: schema.TypeString,
Optional: true,
Description: "The DSV SDK API URL template",
},
},
ConfigureFunc: providerConfig,
}
}