forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_github_organization_role.go
More file actions
82 lines (70 loc) · 1.97 KB
/
data_source_github_organization_role.go
File metadata and controls
82 lines (70 loc) · 1.97 KB
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
package github
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceGithubOrganizationRole() *schema.Resource {
return &schema.Resource{
Description: "Lookup a custom organization role.",
Read: dataSourceGithubOrganizationRoleRead,
Schema: map[string]*schema.Schema{
"role_id": {
Description: "The ID of the organization role.",
Type: schema.TypeInt,
Required: true,
},
"name": {
Description: "The name of the organization role.",
Type: schema.TypeString,
Computed: true,
},
"description": {
Description: "The description of the organization role.",
Type: schema.TypeString,
Computed: true,
},
"source": {
Description: "The source of this role; one of `Predefined`, `Organization`, or `Enterprise`.",
Type: schema.TypeString,
Computed: true,
},
"base_role": {
Description: "The system role from which this role inherits permissions.",
Type: schema.TypeString,
Computed: true,
},
"permissions": {
Description: "A list of permissions included in this role.",
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
},
}
}
func dataSourceGithubOrganizationRoleRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Owner).v3client
ctx := context.Background()
orgName := meta.(*Owner).name
roleId := int64(d.Get("role_id").(int))
role, _, err := client.Organizations.GetOrgRole(ctx, orgName, roleId)
if err != nil {
return err
}
r := map[string]any{
"role_id": role.GetID(),
"name": role.GetName(),
"description": role.GetDescription(),
"source": role.GetSource(),
"base_role": role.GetBaseRole(),
"permissions": role.Permissions,
}
d.SetId(strconv.FormatInt(role.GetID(), 10))
for k, v := range r {
if err := d.Set(k, v); err != nil {
return err
}
}
return nil
}