@@ -10,6 +10,7 @@ import (
1010 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111 "log"
1212 "net/url"
13+ "reflect"
1314 "time"
1415
1516 "github.com/IBM/platform-services-go-sdk/enterprisemanagementv1"
@@ -115,6 +116,9 @@ func dataSourceIbmEnterpriseAccountGroups() *schema.Resource {
115116}
116117
117118func getEnterpriseNext (next * string ) (string , error ) {
119+ if reflect .ValueOf (next ).IsNil () {
120+ return "" , nil
121+ }
118122 u , err := url .Parse (* next )
119123 if err != nil {
120124 return "" , err
@@ -129,25 +133,24 @@ func dataSourceIbmEnterpriseAccountGroupsRead(context context.Context, d *schema
129133 return diag .FromErr (err )
130134 }
131135 next_docid := ""
132- listAccountGroupsOptions := & enterprisemanagementv1.ListAccountGroupsOptions {}
133136 var allRecs []enterprisemanagementv1.AccountGroup
134137 for {
138+ listAccountGroupsOptions := & enterprisemanagementv1.ListAccountGroupsOptions {}
139+ if next_docid != "" {
140+ listAccountGroupsOptions .NextDocid = & next_docid
141+ }
135142 listAccountGroupsResponse , response , err := enterpriseManagementClient .ListAccountGroupsWithContext (context , listAccountGroupsOptions )
136143 if err != nil {
137144 log .Printf ("[DEBUG] ListAccountGroupsWithContext failed %s\n %s" , err , response )
138145 return diag .FromErr (err )
139146 }
147+ next_docid , err = getEnterpriseNext (listAccountGroupsResponse .NextURL )
148+ if err != nil {
149+ log .Printf ("[DEBUG] ListAccountGroupsWithContext failed. Error occurred while parsing NextURL: %s" , err )
150+ return diag .FromErr (err )
151+ }
140152 allRecs = append (allRecs , listAccountGroupsResponse .Resources ... )
141- if listAccountGroupsResponse .NextURL != nil {
142- next_docid , err = getEnterpriseNext (listAccountGroupsResponse .NextURL )
143- if err != nil {
144- log .Printf ("[DEBUG] Error while parsing %s\n %v" , * listAccountGroupsResponse .NextURL , err )
145- return diag .FromErr (err )
146- }
147- listAccountGroupsOptions .NextDocid = & next_docid
148- log .Printf ("[DEBUG] ListAccountsWithContext failed %s" , next_docid )
149- } else {
150- next_docid = ""
153+ if next_docid == "" {
151154 break
152155 }
153156 }
0 commit comments