@@ -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}
0 commit comments