1
1
package gitlab
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"log"
6
7
8
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8
10
"github.com/xanzy/go-gitlab"
9
11
)
10
12
11
13
func dataSourceGitlabGroup () * schema.Resource {
12
14
return & schema.Resource {
13
- Read : dataSourceGitlabGroupRead ,
15
+ ReadContext : dataSourceGitlabGroupRead ,
14
16
Schema : map [string ]* schema.Schema {
15
17
"group_id" : {
16
18
Type : schema .TypeInt ,
@@ -77,7 +79,7 @@ func dataSourceGitlabGroup() *schema.Resource {
77
79
}
78
80
}
79
81
80
- func dataSourceGitlabGroupRead (d * schema.ResourceData , meta interface {}) error {
82
+ func dataSourceGitlabGroupRead (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
81
83
client := meta .(* gitlab.Client )
82
84
83
85
var group * gitlab.Group
@@ -90,18 +92,18 @@ func dataSourceGitlabGroupRead(d *schema.ResourceData, meta interface{}) error {
90
92
91
93
if groupIDOk {
92
94
// 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 ) )
94
96
if err != nil {
95
- return err
97
+ return diag . FromErr ( err )
96
98
}
97
99
} else if fullPathOk {
98
100
// 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 ) )
100
102
if err != nil {
101
- return err
103
+ return diag . FromErr ( err )
102
104
}
103
105
} 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" )
105
107
}
106
108
107
109
d .Set ("group_id" , group .ID )
0 commit comments