-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatasource_client.go
51 lines (41 loc) · 1.1 KB
/
datasource_client.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
package main
import (
"log"
"github.com/DelineaXPM/dsv-sdk-go/v2/vault"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceClientRead(d *schema.ResourceData, meta interface{}) error {
clientID := d.Get("client_id").(string)
dsv, err := vault.New(meta.(vault.Configuration))
if err != nil {
log.Printf("[DEBUG] configuration error: %s", err)
return err
}
log.Printf("[DEBUG] getting client %s", clientID)
client, err := dsv.Client(clientID)
if err != nil {
log.Printf("[DEBUG] unable to get client: %s", err)
return err
}
d.SetId(client.ClientID) // use the ClientID as the (Terraform state) ID
d.Set("client_id", client.ClientID)
d.Set("role", client.RoleName)
return nil
}
func dataSourceClient() *schema.Resource {
return &schema.Resource{
Read: dataSourceClientRead,
Schema: map[string]*schema.Schema{
"role": {
Computed: true,
Description: "the role of the client",
Type: schema.TypeString,
},
"client_id": {
Description: "the client_id of the client",
Computed: true,
Type: schema.TypeString,
},
},
}
}