@@ -5,14 +5,15 @@ import (
55 "fmt"
66
77 "github.com/google/go-github/v67/github"
8+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910)
1011
1112func dataSourceGithubOrganizationRoleTeams () * schema.Resource {
1213 return & schema.Resource {
1314 Description : "Lookup all teams assigned to a custom organization role." ,
1415
15- Read : dataSourceGithubOrganizationRoleTeamsRead ,
16+ ReadContext : dataSourceGithubOrganizationRoleTeamsRead ,
1617
1718 Schema : map [string ]* schema.Schema {
1819 "role_id" : {
@@ -47,7 +48,7 @@ func dataSourceGithubOrganizationRoleTeams() *schema.Resource {
4748 Type : schema .TypeString ,
4849 Computed : true ,
4950 },
50- // TODO: Add these fields when go-github adds the functionality to get a custom org
51+ // TODO: Add these fields when go-github is v68+
5152 // See https://github.com/google/go-github/issues/3364
5253 // "assignment": {
5354 // Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
@@ -71,9 +72,8 @@ func dataSourceGithubOrganizationRoleTeams() *schema.Resource {
7172 }
7273}
7374
74- func dataSourceGithubOrganizationRoleTeamsRead (d * schema.ResourceData , meta any ) error {
75+ func dataSourceGithubOrganizationRoleTeamsRead (ctx context. Context , d * schema.ResourceData , meta any ) diag. Diagnostics {
7576 client := meta .(* Owner ).v3client
76- ctx := context .Background ()
7777 orgName := meta .(* Owner ).name
7878
7979 roleId := int64 (d .Get ("role_id" ).(int ))
@@ -87,7 +87,7 @@ func dataSourceGithubOrganizationRoleTeamsRead(d *schema.ResourceData, meta any)
8787 for {
8888 teams , resp , err := client .Organizations .ListTeamsAssignedToOrgRole (ctx , orgName , roleId , opts )
8989 if err != nil {
90- return err
90+ return diag . FromErr ( err )
9191 }
9292
9393 for _ , team := range teams {
@@ -108,7 +108,7 @@ func dataSourceGithubOrganizationRoleTeamsRead(d *schema.ResourceData, meta any)
108108
109109 d .SetId (fmt .Sprintf ("%d" , roleId ))
110110 if err := d .Set ("teams" , allTeams ); err != nil {
111- return fmt .Errorf ("error setting teams: %w" , err )
111+ return diag . FromErr ( fmt .Errorf ("error setting teams: %w" , err ) )
112112 }
113113
114114 return nil
0 commit comments