Skip to content

Commit 56d091b

Browse files
committed
Use context-aware CRUD functions for Group data source
1 parent 5d4029a commit 56d091b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

gitlab/data_source_gitlab_group.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package gitlab
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67

8+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
810
"github.com/xanzy/go-gitlab"
911
)
1012

1113
func dataSourceGitlabGroup() *schema.Resource {
1214
return &schema.Resource{
13-
Read: dataSourceGitlabGroupRead,
15+
ReadContext: dataSourceGitlabGroupRead,
1416
Schema: map[string]*schema.Schema{
1517
"group_id": {
1618
Type: schema.TypeInt,
@@ -77,7 +79,7 @@ func dataSourceGitlabGroup() *schema.Resource {
7779
}
7880
}
7981

80-
func dataSourceGitlabGroupRead(d *schema.ResourceData, meta interface{}) error {
82+
func dataSourceGitlabGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
8183
client := meta.(*gitlab.Client)
8284

8385
var group *gitlab.Group
@@ -90,18 +92,18 @@ func dataSourceGitlabGroupRead(d *schema.ResourceData, meta interface{}) error {
9092

9193
if groupIDOk {
9294
// Get group by id
93-
group, _, err = client.Groups.GetGroup(groupIDData.(int), nil)
95+
group, _, err = client.Groups.GetGroup(groupIDData.(int), nil, gitlab.WithContext(ctx))
9496
if err != nil {
95-
return err
97+
return diag.FromErr(err)
9698
}
9799
} else if fullPathOk {
98100
// Get group by full path
99-
group, _, err = client.Groups.GetGroup(fullPathData.(string), nil)
101+
group, _, err = client.Groups.GetGroup(fullPathData.(string), nil, gitlab.WithContext(ctx))
100102
if err != nil {
101-
return err
103+
return diag.FromErr(err)
102104
}
103105
} else {
104-
return fmt.Errorf("one and only one of group_id or full_path must be set")
106+
return diag.Errorf("one and only one of group_id or full_path must be set")
105107
}
106108

107109
d.Set("group_id", group.ID)

0 commit comments

Comments
 (0)