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_security_managers.go
More file actions
77 lines (66 loc) · 1.89 KB
/
data_source_github_organization_security_managers.go
File metadata and controls
77 lines (66 loc) · 1.89 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
package github
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceGithubOrganizationSecurityManagers() *schema.Resource {
return &schema.Resource{
DeprecationMessage: "This data source is deprecated in favour of using the github_organization_role_teams data source.",
Read: dataSourceGithubOrganizationSecurityManagersRead,
Schema: map[string]*schema.Schema{
"teams": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Description: "Unique identifier of the team.",
Type: schema.TypeInt,
Computed: true,
},
"slug": {
Description: "Name based identifier of the team.",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Name of the team.",
Type: schema.TypeString,
Computed: true,
},
"permission": {
Description: "Permission that the team will have for its repositories.",
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
func dataSourceGithubOrganizationSecurityManagersRead(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
ctx := context.Background()
orgName := meta.(*Owner).name
allTeams := make([]any, 0)
teams, _, err := client.Organizations.ListSecurityManagerTeams(ctx, orgName)
if err != nil {
return err
}
for _, team := range teams {
t := map[string]any{
"id": team.GetID(),
"slug": team.GetSlug(),
"name": team.GetName(),
"permission": team.GetPermission(),
}
allTeams = append(allTeams, t)
}
d.SetId(fmt.Sprintf("%s/github-org-security-managers", orgName))
if err := d.Set("teams", allTeams); err != nil {
return fmt.Errorf("error setting teams: %w", err)
}
return nil
}