Skip to content

Commit 05b8d03

Browse files
author
Jordan Caussat
committed
Update users datasource: use string builder and rename identities_* parameters to extern_uid & extern_provider
1 parent e10a499 commit 05b8d03

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

gitlab/data_source_gitlab_users.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gitlab
33
import (
44
"fmt"
55
"strconv"
6+
"strings"
67
"time"
78

89
"github.com/hashicorp/terraform/helper/schema"
@@ -40,11 +41,11 @@ func dataSourceGitlabUsers() *schema.Resource {
4041
Type: schema.TypeBool,
4142
Optional: true,
4243
},
43-
"identities_extern_uid": {
44+
"extern_uid": {
4445
Type: schema.TypeString,
4546
Optional: true,
4647
},
47-
"identities_provider": {
48+
"extern_provider": {
4849
Type: schema.TypeString,
4950
Optional: true,
5051
},
@@ -175,71 +176,71 @@ func flattenGitlabUsers(users []*gitlab.User) []interface{} {
175176

176177
func expandGitlabUsersOptions(d *schema.ResourceData) (*gitlab.ListUsersOptions, int, error) {
177178
listUsersOptions := &gitlab.ListUsersOptions{}
178-
optionsHash := ""
179+
var optionsHash strings.Builder
179180

180181
if data, ok := d.GetOk("order_by"); ok {
181182
orderBy := data.(string)
182183
listUsersOptions.OrderBy = &orderBy
183-
optionsHash += orderBy
184+
optionsHash.WriteString(orderBy)
184185
}
185-
optionsHash += ","
186+
optionsHash.WriteString(",")
186187
if data, ok := d.GetOk("sort"); ok {
187188
sort := data.(string)
188189
listUsersOptions.Sort = &sort
189-
optionsHash += sort
190+
optionsHash.WriteString(sort)
190191
}
191-
optionsHash += ","
192+
optionsHash.WriteString(",")
192193
if data, ok := d.GetOk("search"); ok {
193194
search := data.(string)
194195
listUsersOptions.Search = &search
195-
optionsHash += search
196+
optionsHash.WriteString(search)
196197
}
197-
optionsHash += ","
198+
optionsHash.WriteString(",")
198199
if data, ok := d.GetOk("active"); ok {
199200
active := data.(bool)
200201
listUsersOptions.Active = &active
201-
optionsHash += strconv.FormatBool(active)
202+
optionsHash.WriteString(strconv.FormatBool(active))
202203
}
203-
optionsHash += ","
204+
optionsHash.WriteString(",")
204205
if data, ok := d.GetOk("blocked"); ok {
205206
blocked := data.(bool)
206207
listUsersOptions.Blocked = &blocked
207-
optionsHash += strconv.FormatBool(blocked)
208+
optionsHash.WriteString(strconv.FormatBool(blocked))
208209
}
209-
optionsHash += ","
210-
if data, ok := d.GetOk("identities_extern_uid"); ok {
210+
optionsHash.WriteString(",")
211+
if data, ok := d.GetOk("extern_uid"); ok {
211212
externalUID := data.(string)
212213
listUsersOptions.ExternalUID = &externalUID
213-
optionsHash += externalUID
214+
optionsHash.WriteString(externalUID)
214215
}
215-
optionsHash += ","
216-
if data, ok := d.GetOk("identities_provider"); ok {
216+
optionsHash.WriteString(",")
217+
if data, ok := d.GetOk("extern_provider"); ok {
217218
provider := data.(string)
218219
listUsersOptions.Provider = &provider
219-
optionsHash += provider
220+
optionsHash.WriteString(provider)
220221
}
221-
optionsHash += ","
222+
optionsHash.WriteString(",")
222223
if data, ok := d.GetOk("created_before"); ok {
223224
createdBefore := data.(string)
224225
date, err := time.Parse("2006-01-02", createdBefore)
225226
if err != nil {
226227
return nil, 0, fmt.Errorf("created_before must be in yyyy-mm-dd format")
227228
}
228229
listUsersOptions.CreatedBefore = &date
229-
optionsHash += createdBefore
230+
optionsHash.WriteString(createdBefore)
230231
}
231-
optionsHash += ","
232+
optionsHash.WriteString(",")
232233
if data, ok := d.GetOk("created_after"); ok {
233234
createdAfter := data.(string)
234235
date, err := time.Parse("2006-01-02", createdAfter)
235236
if err != nil {
236237
return nil, 0, fmt.Errorf("created_after must be in yyyy-mm-dd format")
237238
}
238239
listUsersOptions.CreatedAfter = &date
239-
optionsHash += createdAfter
240+
optionsHash.WriteString(createdAfter)
240241
}
241242

242-
id := schema.HashString(optionsHash)
243+
id := schema.HashString(optionsHash.String())
243244

244245
return listUsersOptions, id, nil
245246
}

0 commit comments

Comments
 (0)