-
Notifications
You must be signed in to change notification settings - Fork 3
/
datasource_role.go
76 lines (66 loc) · 1.65 KB
/
datasource_role.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
package main
import (
"log"
"github.com/DelineaXPM/dsv-sdk-go/v2/vault"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceRoleRead(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
dsv, err := vault.New(meta.(vault.Configuration))
if err != nil {
log.Printf("[DEBUG] configuration error: %s", err)
return err
}
log.Printf("[DEBUG] getting role %s", name)
role, err := dsv.Role(name)
if err != nil {
log.Printf("[DEBUG] unable to get role: %s", err)
return err
}
d.SetId(role.ID)
d.Set("role_provider", role.Provider)
d.Set("external_id", role.ExternalID)
d.Set("groups", role.Groups)
d.Set("version", role.Version)
return nil
}
func dataSourceRole() *schema.Resource {
return &schema.Resource{
Read: dataSourceRoleRead,
Schema: map[string]*schema.Schema{
"role_provider": {
Computed: true,
Description: "the provider of the role",
Type: schema.TypeString,
},
"external_id": {
Computed: true,
Description: "the external-id of the role",
Type: schema.TypeString,
},
"groups": {
Computed: true,
Description: "the groups associated with the role",
Elem: &schema.Schema{
Type: schema.TypeString,
},
Type: schema.TypeSet,
},
"name": {
Description: "the name of the role",
Required: true,
Type: schema.TypeString,
},
"id": {
Computed: true,
Description: "the (UUID) identifier of the role",
Type: schema.TypeString,
},
"version": {
Computed: true,
Description: "the version of the role",
Type: schema.TypeInt,
},
},
}
}