33package gitlab
44
55import (
6+ "context"
67 "fmt"
78 "log"
89
10+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
911 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1012 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1113 "github.com/mitchellh/hashstructure"
@@ -172,7 +174,7 @@ func flattenProjects(projects []*gitlab.Project) (values []map[string]interface{
172174func dataSourceGitlabProjects () * schema.Resource {
173175 // lintignore: S024 // TODO: Resolve this tfproviderlint issue
174176 return & schema.Resource {
175- Read : dataSourceGitlabProjectsRead ,
177+ ReadContext : dataSourceGitlabProjectsRead ,
176178
177179 // lintignore: S006 // TODO: Resolve this tfproviderlint issue
178180 Schema : map [string ]* schema.Schema {
@@ -673,7 +675,7 @@ func dataSourceGitlabProjects() *schema.Resource {
673675
674676// CRUD methods
675677
676- func dataSourceGitlabProjectsRead (d * schema.ResourceData , meta interface {}) ( err error ) {
678+ func dataSourceGitlabProjectsRead (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
677679 client := meta .(* gitlab.Client )
678680 var projectList []* gitlab.Project
679681
@@ -797,9 +799,9 @@ func dataSourceGitlabProjectsRead(d *schema.ResourceData, meta interface{}) (err
797799 }
798800
799801 for {
800- projects , response , err := client .Groups .ListGroupProjects (groupId .(int ), opts , nil )
802+ projects , response , err := client .Groups .ListGroupProjects (groupId .(int ), opts , gitlab . WithContext ( ctx ) )
801803 if err != nil {
802- return err
804+ return diag . FromErr ( err )
803805 }
804806 projectList = append (projectList , projects ... )
805807 opts .ListOptions .Page ++
@@ -811,11 +813,11 @@ func dataSourceGitlabProjectsRead(d *schema.ResourceData, meta interface{}) (err
811813 }
812814 h , err := hashstructure .Hash (* opts , nil )
813815 if err != nil {
814- return err
816+ return diag . FromErr ( err )
815817 }
816818 d .SetId (fmt .Sprintf ("%d-%d" , groupId .(int ), h ))
817819 if err := d .Set ("projects" , flattenProjects (projectList )); err != nil {
818- return err
820+ return diag . FromErr ( err )
819821 }
820822
821823 // Project case
@@ -843,9 +845,9 @@ func dataSourceGitlabProjectsRead(d *schema.ResourceData, meta interface{}) (err
843845 }
844846
845847 for {
846- projects , response , err := client .Projects .ListProjects (opts , nil )
848+ projects , response , err := client .Projects .ListProjects (opts , nil , gitlab . WithContext ( ctx ) )
847849 if err != nil {
848- return err
850+ return diag . FromErr ( err )
849851 }
850852 projectList = append (projectList , projects ... )
851853 opts .ListOptions .Page ++
@@ -857,14 +859,15 @@ func dataSourceGitlabProjectsRead(d *schema.ResourceData, meta interface{}) (err
857859 }
858860 h , err := hashstructure .Hash (* opts , nil )
859861 if err != nil {
860- return err
862+ return diag . FromErr ( err )
861863 }
862864 d .SetId (fmt .Sprintf ("%d" , h ))
863865 if err := d .Set ("projects" , flattenProjects (projectList )); err != nil {
864- return err
866+ return diag . FromErr ( err )
865867 }
866868 }
867- return err
869+
870+ return nil
868871}
869872
870873func flattenSharedWithGroupsOptions (project * gitlab.Project ) []interface {} {
0 commit comments