Skip to content

Commit dbc4e65

Browse files
committed
chore(postgresflex): use new multi API version support SDK - part2
1 parent 34290e2 commit dbc4e65

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

stackit/internal/services/postgresflex/database/datasource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
1717

1818
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
19-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
19+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
2020
)
2121

2222
// Ensure the implementation satisfies the expected interfaces.

stackit/internal/services/postgresflex/database/resource.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2323
"github.com/hashicorp/terraform-plugin-framework/types"
2424
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
25-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
25+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
2626
)
2727

2828
// Ensure the implementation satisfies the expected interfaces.
@@ -214,7 +214,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
214214
return
215215
}
216216
// Create new database
217-
databaseResp, err := r.client.CreateDatabase(ctx, projectId, region, instanceId).CreateDatabasePayload(*payload).Execute()
217+
databaseResp, err := r.client.DefaultAPI.CreateDatabase(ctx, projectId, region, instanceId).CreateDatabasePayload(*payload).Execute()
218218
if err != nil {
219219
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating database", fmt.Sprintf("Calling API: %v", err))
220220
return
@@ -327,7 +327,7 @@ func (r *databaseResource) Delete(ctx context.Context, req resource.DeleteReques
327327
ctx = tflog.SetField(ctx, "region", region)
328328

329329
// Delete existing record set
330-
err := r.client.DeleteDatabase(ctx, projectId, region, instanceId, databaseId).Execute()
330+
err := r.client.DefaultAPI.DeleteDatabase(ctx, projectId, region, instanceId, databaseId).Execute()
331331
if err != nil {
332332
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting database", fmt.Sprintf("Calling API: %v", err))
333333
}
@@ -389,7 +389,7 @@ func mapFields(databaseResp *postgresflex.InstanceDatabase, model *Model, region
389389
model.Region = types.StringValue(region)
390390

391391
if databaseResp.Options != nil {
392-
owner, ok := (*databaseResp.Options)["owner"]
392+
owner, ok := (databaseResp.Options)["owner"]
393393
if ok {
394394
ownerStr, ok := owner.(string)
395395
if !ok {
@@ -422,14 +422,14 @@ var errDatabaseNotFound = errors.New("database not found")
422422

423423
// The API does not have a GetDatabase endpoint, only ListDatabases
424424
func getDatabase(ctx context.Context, client *postgresflex.APIClient, projectId, region, instanceId, databaseId string) (*postgresflex.InstanceDatabase, error) {
425-
resp, err := client.ListDatabases(ctx, projectId, region, instanceId).Execute()
425+
resp, err := client.DefaultAPI.ListDatabases(ctx, projectId, region, instanceId).Execute()
426426
if err != nil {
427427
return nil, err
428428
}
429429
if resp == nil || resp.Databases == nil {
430430
return nil, fmt.Errorf("response is nil")
431431
}
432-
for _, database := range *resp.Databases {
432+
for _, database := range resp.Databases {
433433
if database.Id != nil && *database.Id == databaseId {
434434
return &database, nil
435435
}

stackit/internal/services/postgresflex/database/resource_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/google/go-cmp/cmp"
77
"github.com/hashicorp/terraform-plugin-framework/types"
8-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
8+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
99
)
1010

1111
func TestMapFields(t *testing.T) {
@@ -39,7 +39,7 @@ func TestMapFields(t *testing.T) {
3939
&postgresflex.InstanceDatabase{
4040
Id: new("uid"),
4141
Name: new("dbname"),
42-
Options: &map[string]any{
42+
Options: map[string]any{
4343
"owner": "username",
4444
},
4545
},
@@ -60,7 +60,7 @@ func TestMapFields(t *testing.T) {
6060
&postgresflex.InstanceDatabase{
6161
Id: new("uid"),
6262
Name: new(""),
63-
Options: &map[string]any{
63+
Options: map[string]any{
6464
"owner": "",
6565
},
6666
},
@@ -95,7 +95,7 @@ func TestMapFields(t *testing.T) {
9595
&postgresflex.InstanceDatabase{
9696
Id: new(""),
9797
Name: new("dbname"),
98-
Options: &map[string]any{
98+
Options: map[string]any{
9999
"owner": "username",
100100
},
101101
},

stackit/internal/services/postgresflex/user/datasource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
2020
"github.com/hashicorp/terraform-plugin-framework/types"
21-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
21+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
2222
)
2323

2424
// Ensure the implementation satisfies the expected interfaces.
@@ -153,7 +153,7 @@ func (r *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
153153
ctx = tflog.SetField(ctx, "user_id", userId)
154154
ctx = tflog.SetField(ctx, "region", region)
155155

156-
recordSetResp, err := r.client.GetUser(ctx, projectId, region, instanceId, userId).Execute()
156+
recordSetResp, err := r.client.DefaultAPI.GetUser(ctx, projectId, region, instanceId, userId).Execute()
157157
if err != nil {
158158
utils.LogError(
159159
ctx,
@@ -214,7 +214,7 @@ func mapDataSourceFields(userResp *postgresflex.GetUserResponse, model *DataSour
214214
model.Roles = types.SetNull(types.StringType)
215215
} else {
216216
roles := []attr.Value{}
217-
for _, role := range *user.Roles {
217+
for _, role := range user.Roles {
218218
roles = append(roles, types.StringValue(role))
219219
}
220220
rolesSet, diags := types.SetValue(types.StringType, roles)

stackit/internal/services/postgresflex/user/datasource_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/google/go-cmp/cmp"
77
"github.com/hashicorp/terraform-plugin-framework/attr"
88
"github.com/hashicorp/terraform-plugin-framework/types"
9-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
9+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
1010
)
1111

1212
func TestMapDataSourceFields(t *testing.T) {
@@ -41,7 +41,7 @@ func TestMapDataSourceFields(t *testing.T) {
4141
"simple_values",
4242
&postgresflex.GetUserResponse{
4343
Item: &postgresflex.UserResponse{
44-
Roles: &[]string{
44+
Roles: []string{
4545
"role_1",
4646
"role_2",
4747
"",
@@ -74,7 +74,7 @@ func TestMapDataSourceFields(t *testing.T) {
7474
&postgresflex.GetUserResponse{
7575
Item: &postgresflex.UserResponse{
7676
Id: new("uid"),
77-
Roles: &[]string{},
77+
Roles: []string{},
7878
Username: nil,
7979
Host: nil,
8080
Port: new(int64(2123456789)),

stackit/internal/services/postgresflex/user/resource.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2424
"github.com/hashicorp/terraform-plugin-framework/types"
2525
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
26-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
27-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait"
26+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
27+
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/wait"
2828
)
2929

3030
// Ensure the implementation satisfies the expected interfaces.
@@ -239,7 +239,7 @@ func (r *userResource) Create(ctx context.Context, req resource.CreateRequest, r
239239
return
240240
}
241241
// Create new user
242-
userResp, err := r.client.CreateUser(ctx, projectId, region, instanceId).CreateUserPayload(*payload).Execute()
242+
userResp, err := r.client.DefaultAPI.CreateUser(ctx, projectId, region, instanceId).CreateUserPayload(*payload).Execute()
243243
if err != nil {
244244
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err))
245245
return
@@ -289,7 +289,7 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp
289289
ctx = tflog.SetField(ctx, "user_id", userId)
290290
ctx = tflog.SetField(ctx, "region", region)
291291

292-
recordSetResp, err := r.client.GetUser(ctx, projectId, region, instanceId, userId).Execute()
292+
recordSetResp, err := r.client.DefaultAPI.GetUser(ctx, projectId, region, instanceId, userId).Execute()
293293
if err != nil {
294294
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
295295
if ok && oapiErr.StatusCode == http.StatusNotFound {
@@ -364,15 +364,15 @@ func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, r
364364
}
365365

366366
// Update existing instance
367-
err = r.client.UpdateUser(ctx, projectId, region, instanceId, userId).UpdateUserPayload(*payload).Execute()
367+
err = r.client.DefaultAPI.UpdateUser(ctx, projectId, region, instanceId, userId).UpdateUserPayload(*payload).Execute()
368368
if err != nil {
369369
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", err.Error())
370370
return
371371
}
372372

373373
ctx = core.LogResponse(ctx)
374374

375-
userResp, err := r.client.GetUser(ctx, projectId, region, instanceId, userId).Execute()
375+
userResp, err := r.client.DefaultAPI.GetUser(ctx, projectId, region, instanceId, userId).Execute()
376376
if err != nil {
377377
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", fmt.Sprintf("Calling API: %v", err))
378378
return
@@ -416,14 +416,14 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r
416416
ctx = tflog.SetField(ctx, "region", region)
417417

418418
// Delete existing record set
419-
err := r.client.DeleteUser(ctx, projectId, region, instanceId, userId).Execute()
419+
err := r.client.DefaultAPI.DeleteUser(ctx, projectId, region, instanceId, userId).Execute()
420420
if err != nil {
421421
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err))
422422
}
423423

424424
ctx = core.LogResponse(ctx)
425425

426-
_, err = wait.DeleteUserWaitHandler(ctx, r.client, projectId, region, instanceId, userId).WaitWithContext(ctx)
426+
_, err = wait.DeleteUserWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId, userId).WaitWithContext(ctx)
427427
if err != nil {
428428
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Instance deletion waiting: %v", err))
429429
return
@@ -482,7 +482,7 @@ func mapFieldsCreate(userResp *postgresflex.CreateUserResponse, model *Model, re
482482
model.Roles = types.SetNull(types.StringType)
483483
} else {
484484
roles := []attr.Value{}
485-
for _, role := range *user.Roles {
485+
for _, role := range user.Roles {
486486
roles = append(roles, types.StringValue(role))
487487
}
488488
rolesSet, diags := types.SetValue(types.StringType, roles)
@@ -525,7 +525,7 @@ func mapFields(userResp *postgresflex.GetUserResponse, model *Model, region stri
525525
model.Roles = types.SetNull(types.StringType)
526526
} else {
527527
roles := []attr.Value{}
528-
for _, role := range *user.Roles {
528+
for _, role := range user.Roles {
529529
roles = append(roles, types.StringValue(role))
530530
}
531531
rolesSet, diags := types.SetValue(types.StringType, roles)
@@ -549,7 +549,7 @@ func toCreatePayload(model *Model, roles []string) (*postgresflex.CreateUserPayl
549549
}
550550

551551
return &postgresflex.CreateUserPayload{
552-
Roles: &roles,
552+
Roles: roles,
553553
Username: conversion.StringValueToPointer(model.Username),
554554
}, nil
555555
}
@@ -563,6 +563,6 @@ func toUpdatePayload(model *Model, roles []string) (*postgresflex.UpdateUserPayl
563563
}
564564

565565
return &postgresflex.UpdateUserPayload{
566-
Roles: &roles,
566+
Roles: roles,
567567
}, nil
568568
}

stackit/internal/services/postgresflex/user/resource_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/google/go-cmp/cmp"
77
"github.com/hashicorp/terraform-plugin-framework/attr"
88
"github.com/hashicorp/terraform-plugin-framework/types"
9-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
9+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
1010
)
1111

1212
func TestMapFieldsCreate(t *testing.T) {
@@ -47,7 +47,7 @@ func TestMapFieldsCreate(t *testing.T) {
4747
&postgresflex.CreateUserResponse{
4848
Item: &postgresflex.User{
4949
Id: new("uid"),
50-
Roles: &[]string{
50+
Roles: []string{
5151
"role_1",
5252
"role_2",
5353
"",
@@ -84,7 +84,7 @@ func TestMapFieldsCreate(t *testing.T) {
8484
&postgresflex.CreateUserResponse{
8585
Item: &postgresflex.User{
8686
Id: new("uid"),
87-
Roles: &[]string{},
87+
Roles: []string{},
8888
Username: nil,
8989
Password: new(""),
9090
Host: nil,
@@ -198,7 +198,7 @@ func TestMapFields(t *testing.T) {
198198
"simple_values",
199199
&postgresflex.GetUserResponse{
200200
Item: &postgresflex.UserResponse{
201-
Roles: &[]string{
201+
Roles: []string{
202202
"role_1",
203203
"role_2",
204204
"",
@@ -231,7 +231,7 @@ func TestMapFields(t *testing.T) {
231231
&postgresflex.GetUserResponse{
232232
Item: &postgresflex.UserResponse{
233233
Id: new("uid"),
234-
Roles: &[]string{},
234+
Roles: []string{},
235235
Username: nil,
236236
Host: nil,
237237
Port: new(int64(2123456789)),
@@ -312,7 +312,7 @@ func TestToCreatePayload(t *testing.T) {
312312
&Model{},
313313
[]string{},
314314
&postgresflex.CreateUserPayload{
315-
Roles: &[]string{},
315+
Roles: []string{},
316316
Username: nil,
317317
},
318318
true,
@@ -327,7 +327,7 @@ func TestToCreatePayload(t *testing.T) {
327327
"role_2",
328328
},
329329
&postgresflex.CreateUserPayload{
330-
Roles: &[]string{
330+
Roles: []string{
331331
"role_1",
332332
"role_2",
333333
},
@@ -344,7 +344,7 @@ func TestToCreatePayload(t *testing.T) {
344344
"",
345345
},
346346
&postgresflex.CreateUserPayload{
347-
Roles: &[]string{
347+
Roles: []string{
348348
"",
349349
},
350350
Username: nil,
@@ -398,7 +398,7 @@ func TestToUpdatePayload(t *testing.T) {
398398
&Model{},
399399
[]string{},
400400
&postgresflex.UpdateUserPayload{
401-
Roles: &[]string{},
401+
Roles: []string{},
402402
},
403403
true,
404404
},
@@ -412,7 +412,7 @@ func TestToUpdatePayload(t *testing.T) {
412412
"role_2",
413413
},
414414
&postgresflex.UpdateUserPayload{
415-
Roles: &[]string{
415+
Roles: []string{
416416
"role_1",
417417
"role_2",
418418
},
@@ -428,7 +428,7 @@ func TestToUpdatePayload(t *testing.T) {
428428
"",
429429
},
430430
&postgresflex.UpdateUserPayload{
431-
Roles: &[]string{
431+
Roles: []string{
432432
"",
433433
},
434434
},

0 commit comments

Comments
 (0)