Skip to content

Commit 2973fa0

Browse files
committed
chore(redis): use new multi API version support SDK
1 parent 546d5a8 commit 2973fa0

11 files changed

Lines changed: 230 additions & 232 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.26.1
3232
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5
3333
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0
34-
github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6
34+
github.com/stackitcloud/stackit-sdk-go/services/redis v0.27.3
3535
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.0
3636
github.com/stackitcloud/stackit-sdk-go/services/scf v0.6.1
3737
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.14.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0 h1:/8lmviszgrB+
195195
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0/go.mod h1:hnhvlLX1Y71R8KIQqLBeoSZqkU5ZJOG0J4wz0LeUdaw=
196196
github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6 h1:CXM9cZ9WeTyJd+Aw/hnJnDsKRVAQi4qgtd0RJ3zoPwo=
197197
github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6/go.mod h1:KJNceOHRefjku1oVBoHG7idCS/SeW42WJ+55bN3AxrQ=
198+
github.com/stackitcloud/stackit-sdk-go/services/redis v0.27.3 h1:wZIGETPQ1aiJwzJMVjatdu/Kv+/yuKVOf5RaMWW9bpU=
199+
github.com/stackitcloud/stackit-sdk-go/services/redis v0.27.3/go.mod h1:jgWx29zvZP0R3tXAC/qWU5eBsPfLBJFP96mx9hwdFPM=
198200
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.0 h1:bT/qoghsdKvLomCay9Wj4Fu63lx0cD2zr23Fjqzgotc=
199201
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.0/go.mod h1:jiPIzF8lcm5Dx0TkDK2CBgeRBHSRUqwyX+z/zqo1bes=
200202
github.com/stackitcloud/stackit-sdk-go/services/scf v0.6.1 h1:ayfCRRVTVwFGQMfjmXaDhiLyif53ibTu7zNhUTnNh2w=

stackit/internal/services/redis/credential/datasource.go

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

1818
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
1919
"github.com/hashicorp/terraform-plugin-framework/types"
20-
"github.com/stackitcloud/stackit-sdk-go/services/redis"
20+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v1api"
2121
)
2222

2323
// Ensure the implementation satisfies the expected interfaces.
@@ -111,7 +111,7 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
111111
Computed: true,
112112
Sensitive: true,
113113
},
114-
"port": schema.Int64Attribute{
114+
"port": schema.Int32Attribute{
115115
Computed: true,
116116
},
117117
"uri": schema.StringAttribute{
@@ -144,7 +144,7 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ
144144
ctx = tflog.SetField(ctx, "instance_id", instanceId)
145145
ctx = tflog.SetField(ctx, "credential_id", credentialId)
146146

147-
recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute()
147+
recordSetResp, err := r.client.DefaultAPI.GetCredentials(ctx, projectId, instanceId, credentialId).Execute()
148148
if err != nil {
149149
utils.LogError(
150150
ctx,

stackit/internal/services/redis/credential/resource.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2222
"github.com/hashicorp/terraform-plugin-framework/types"
2323
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
24-
"github.com/stackitcloud/stackit-sdk-go/services/redis"
25-
"github.com/stackitcloud/stackit-sdk-go/services/redis/wait"
24+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v1api"
25+
"github.com/stackitcloud/stackit-sdk-go/services/redis/v1api/wait"
2626
)
2727

2828
// Ensure the implementation satisfies the expected interfaces.
@@ -41,7 +41,7 @@ type Model struct {
4141
Hosts types.List `tfsdk:"hosts"`
4242
LoadBalancedHost types.String `tfsdk:"load_balanced_host"`
4343
Password types.String `tfsdk:"password"`
44-
Port types.Int64 `tfsdk:"port"`
44+
Port types.Int32 `tfsdk:"port"`
4545
Uri types.String `tfsdk:"uri"`
4646
Username types.String `tfsdk:"username"`
4747
}
@@ -146,7 +146,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest,
146146
Computed: true,
147147
Sensitive: true,
148148
},
149-
"port": schema.Int64Attribute{
149+
"port": schema.Int32Attribute{
150150
Computed: true,
151151
},
152152
"uri": schema.StringAttribute{
@@ -178,19 +178,19 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
178178
ctx = tflog.SetField(ctx, "instance_id", instanceId)
179179

180180
// Create new recordset
181-
credentialsResp, err := r.client.CreateCredentials(ctx, projectId, instanceId).Execute()
181+
credentialsResp, err := r.client.DefaultAPI.CreateCredentials(ctx, projectId, instanceId).Execute()
182182
if err != nil {
183183
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Calling API: %v", err))
184184
return
185185
}
186186

187187
ctx = core.LogResponse(ctx)
188188

189-
if credentialsResp.Id == nil {
189+
if credentialsResp.Id == "" {
190190
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id")
191191
return
192192
}
193-
credentialId := *credentialsResp.Id
193+
credentialId := credentialsResp.Id
194194
// Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
195195
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
196196
"project_id": projectId,
@@ -201,7 +201,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
201201
return
202202
}
203203

204-
waitResp, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).WaitWithContext(ctx)
204+
waitResp, err := wait.CreateCredentialsWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, credentialId).WaitWithContext(ctx)
205205
if err != nil {
206206
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Instance creation waiting: %v", err))
207207
return
@@ -239,7 +239,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
239239
ctx = tflog.SetField(ctx, "instance_id", instanceId)
240240
ctx = tflog.SetField(ctx, "credential_id", credentialId)
241241

242-
recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute()
242+
recordSetResp, err := r.client.DefaultAPI.GetCredentials(ctx, projectId, instanceId, credentialId).Execute()
243243
if err != nil {
244244
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
245245
if ok && oapiErr.StatusCode == http.StatusNotFound {
@@ -293,14 +293,14 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
293293
ctx = tflog.SetField(ctx, "credential_id", credentialId)
294294

295295
// Delete existing record set
296-
err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute()
296+
err := r.client.DefaultAPI.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute()
297297
if err != nil {
298298
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err))
299299
}
300300

301301
ctx = core.LogResponse(ctx)
302302

303-
_, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).WaitWithContext(ctx)
303+
_, err = wait.DeleteCredentialsWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, credentialId).WaitWithContext(ctx)
304304
if err != nil {
305305
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Instance deletion waiting: %v", err))
306306
return
@@ -343,8 +343,8 @@ func mapFields(ctx context.Context, credentialsResp *redis.CredentialsResponse,
343343
var credentialId string
344344
if model.CredentialId.ValueString() != "" {
345345
credentialId = model.CredentialId.ValueString()
346-
} else if credentialsResp.Id != nil {
347-
credentialId = *credentialsResp.Id
346+
} else if credentialsResp.Id != "" {
347+
credentialId = credentialsResp.Id
348348
} else {
349349
return fmt.Errorf("credentials id not present")
350350
}
@@ -356,27 +356,27 @@ func mapFields(ctx context.Context, credentialsResp *redis.CredentialsResponse,
356356
return err
357357
}
358358

359-
model.CredentialId = types.StringValue(credentialId)
360359
model.Hosts = types.ListNull(types.StringType)
361-
if credentials != nil {
362-
if credentials.Hosts != nil {
363-
respHosts := *credentials.Hosts
360+
model.CredentialId = types.StringValue(credentialId)
364361

365-
reconciledHosts := utils.ReconcileStringSlices(modelHosts, respHosts)
362+
if credentials.Hosts != nil {
363+
respHosts := credentials.Hosts
366364

367-
hostsTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledHosts)
368-
if diags.HasError() {
369-
return fmt.Errorf("failed to map hosts: %w", core.DiagsToError(diags))
370-
}
365+
reconciledHosts := utils.ReconcileStringSlices(modelHosts, respHosts)
371366

372-
model.Hosts = hostsTF
367+
hostsTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledHosts)
368+
if diags.HasError() {
369+
return fmt.Errorf("failed to map hosts: %w", core.DiagsToError(diags))
373370
}
374-
model.Host = types.StringPointerValue(credentials.Host)
375-
model.LoadBalancedHost = types.StringPointerValue(credentials.LoadBalancedHost)
376-
model.Password = types.StringPointerValue(credentials.Password)
377-
model.Port = types.Int64PointerValue(credentials.Port)
378-
model.Uri = types.StringPointerValue(credentials.Uri)
379-
model.Username = types.StringPointerValue(credentials.Username)
371+
372+
model.Hosts = hostsTF
380373
}
374+
model.Host = types.StringValue(credentials.Host)
375+
model.LoadBalancedHost = types.StringPointerValue(credentials.LoadBalancedHost)
376+
model.Password = types.StringValue(credentials.Password)
377+
model.Port = types.Int32PointerValue(credentials.Port)
378+
model.Uri = types.StringPointerValue(credentials.Uri)
379+
model.Username = types.StringValue(credentials.Username)
380+
381381
return nil
382382
}

stackit/internal/services/redis/credential/resource_test.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/google/go-cmp/cmp"
88
"github.com/hashicorp/terraform-plugin-framework/attr"
99
"github.com/hashicorp/terraform-plugin-framework/types"
10-
"github.com/stackitcloud/stackit-sdk-go/services/redis"
10+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v1api"
1111
)
1212

1313
func TestMapFields(t *testing.T) {
@@ -25,21 +25,21 @@ func TestMapFields(t *testing.T) {
2525
ProjectId: types.StringValue("pid"),
2626
},
2727
&redis.CredentialsResponse{
28-
Id: new("cid"),
28+
Id: "cid",
2929
Raw: &redis.RawCredentials{},
3030
},
3131
Model{
3232
Id: types.StringValue("pid,iid,cid"),
3333
CredentialId: types.StringValue("cid"),
3434
InstanceId: types.StringValue("iid"),
3535
ProjectId: types.StringValue("pid"),
36-
Host: types.StringNull(),
36+
Host: types.StringValue(""),
3737
Hosts: types.ListNull(types.StringType),
3838
LoadBalancedHost: types.StringNull(),
39-
Password: types.StringNull(),
40-
Port: types.Int64Null(),
39+
Password: types.StringValue(""),
40+
Port: types.Int32Null(),
4141
Uri: types.StringNull(),
42-
Username: types.StringNull(),
42+
Username: types.StringValue(""),
4343
},
4444
true,
4545
},
@@ -50,19 +50,19 @@ func TestMapFields(t *testing.T) {
5050
ProjectId: types.StringValue("pid"),
5151
},
5252
&redis.CredentialsResponse{
53-
Id: new("cid"),
53+
Id: "cid",
5454
Raw: &redis.RawCredentials{
55-
Credentials: &redis.Credentials{
56-
Host: new("host"),
57-
Hosts: &[]string{
55+
Credentials: redis.Credentials{
56+
Host: "host",
57+
Hosts: []string{
5858
"host_1",
5959
"",
6060
},
6161
LoadBalancedHost: new("load_balanced_host"),
62-
Password: new("password"),
63-
Port: new(int64(1234)),
62+
Password: "password",
63+
Port: new(int32(1234)),
6464
Uri: new("uri"),
65-
Username: new("username"),
65+
Username: "username",
6666
},
6767
},
6868
},
@@ -78,7 +78,7 @@ func TestMapFields(t *testing.T) {
7878
}),
7979
LoadBalancedHost: types.StringValue("load_balanced_host"),
8080
Password: types.StringValue("password"),
81-
Port: types.Int64Value(1234),
81+
Port: types.Int32Value(1234),
8282
Uri: types.StringValue("uri"),
8383
Username: types.StringValue("username"),
8484
},
@@ -96,20 +96,20 @@ func TestMapFields(t *testing.T) {
9696
}),
9797
},
9898
&redis.CredentialsResponse{
99-
Id: new("cid"),
99+
Id: "cid",
100100
Raw: &redis.RawCredentials{
101-
Credentials: &redis.Credentials{
102-
Host: new("host"),
103-
Hosts: &[]string{
101+
Credentials: redis.Credentials{
102+
Host: "host",
103+
Hosts: []string{
104104
"",
105105
"host_1",
106106
"host_2",
107107
},
108108
LoadBalancedHost: new("load_balanced_host"),
109-
Password: new("password"),
110-
Port: new(int64(1234)),
109+
Password: "password",
110+
Port: new(int32(1234)),
111111
Uri: new("uri"),
112-
Username: new("username"),
112+
Username: "username",
113113
},
114114
},
115115
},
@@ -126,7 +126,7 @@ func TestMapFields(t *testing.T) {
126126
}),
127127
LoadBalancedHost: types.StringValue("load_balanced_host"),
128128
Password: types.StringValue("password"),
129-
Port: types.Int64Value(1234),
129+
Port: types.Int32Value(1234),
130130
Uri: types.StringValue("uri"),
131131
Username: types.StringValue("username"),
132132
},
@@ -139,16 +139,16 @@ func TestMapFields(t *testing.T) {
139139
ProjectId: types.StringValue("pid"),
140140
},
141141
&redis.CredentialsResponse{
142-
Id: new("cid"),
142+
Id: "cid",
143143
Raw: &redis.RawCredentials{
144-
Credentials: &redis.Credentials{
145-
Host: new(""),
146-
Hosts: &[]string{},
144+
Credentials: redis.Credentials{
145+
Host: "",
146+
Hosts: []string{},
147147
LoadBalancedHost: nil,
148-
Password: new(""),
149-
Port: new(int64(2123456789)),
148+
Password: "",
149+
Port: new(int32(2123456789)),
150150
Uri: nil,
151-
Username: new(""),
151+
Username: "",
152152
},
153153
},
154154
},
@@ -161,7 +161,7 @@ func TestMapFields(t *testing.T) {
161161
Hosts: types.ListValueMust(types.StringType, []attr.Value{}),
162162
LoadBalancedHost: types.StringNull(),
163163
Password: types.StringValue(""),
164-
Port: types.Int64Value(2123456789),
164+
Port: types.Int32Value(2123456789),
165165
Uri: types.StringNull(),
166166
Username: types.StringValue(""),
167167
},
@@ -194,7 +194,7 @@ func TestMapFields(t *testing.T) {
194194
ProjectId: types.StringValue("pid"),
195195
},
196196
&redis.CredentialsResponse{
197-
Id: new("cid"),
197+
Id: "cid",
198198
},
199199
Model{},
200200
false,

0 commit comments

Comments
 (0)