@@ -22,8 +22,8 @@ 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/rabbitmq"
26- "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/wait"
25+ rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api "
26+ "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api/ wait"
2727)
2828
2929// Ensure the implementation satisfies the expected interfaces.
@@ -44,7 +44,7 @@ type Model struct {
4444 HttpAPIURIs types.List `tfsdk:"http_api_uris"`
4545 Management types.String `tfsdk:"management"`
4646 Password types.String `tfsdk:"password"`
47- Port types.Int64 `tfsdk:"port"`
47+ Port types.Int32 `tfsdk:"port"`
4848 Uri types.String `tfsdk:"uri"`
4949 Uris types.List `tfsdk:"uris"`
5050 Username types.String `tfsdk:"username"`
@@ -156,7 +156,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest,
156156 Computed : true ,
157157 Sensitive : true ,
158158 },
159- "port" : schema.Int64Attribute {
159+ "port" : schema.Int32Attribute {
160160 Computed : true ,
161161 },
162162 "uri" : schema.StringAttribute {
@@ -191,19 +191,19 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
191191 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
192192
193193 // Create new recordset
194- credentialsResp , err := r .client .CreateCredentials (ctx , projectId , instanceId ).Execute ()
194+ credentialsResp , err := r .client .DefaultAPI . CreateCredentials (ctx , projectId , instanceId ).Execute ()
195195 if err != nil {
196196 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Calling API: %v" , err ))
197197 return
198198 }
199199
200200 ctx = core .LogResponse (ctx )
201201
202- if credentialsResp .Id == nil {
202+ if credentialsResp .Id == "" {
203203 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , "Got empty credential id" )
204204 return
205205 }
206- credentialId := * credentialsResp .Id
206+ credentialId := credentialsResp .Id
207207 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
208208 "project_id" : projectId ,
209209 "instance_id" : instanceId ,
@@ -213,7 +213,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
213213 return
214214 }
215215
216- waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
216+ waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
217217 if err != nil {
218218 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Instance creation waiting: %v" , err ))
219219 return
@@ -251,7 +251,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
251251 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
252252 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
253253
254- recordSetResp , err := r .client .GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
254+ recordSetResp , err := r .client .DefaultAPI . GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
255255 if err != nil {
256256 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
257257 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -305,14 +305,14 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
305305 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
306306
307307 // Delete existing record set
308- err := r .client .DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
308+ err := r .client .DefaultAPI . DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
309309 if err != nil {
310310 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Calling API: %v" , err ))
311311 }
312312
313313 ctx = core .LogResponse (ctx )
314314
315- _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
315+ _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
316316 if err != nil {
317317 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
318318 return
@@ -358,8 +358,8 @@ func mapFields(ctx context.Context, credentialsResp *rabbitmq.CredentialsRespons
358358 var credentialId string
359359 if model .CredentialId .ValueString () != "" {
360360 credentialId = model .CredentialId .ValueString ()
361- } else if credentialsResp .Id != nil {
362- credentialId = * credentialsResp .Id
361+ } else if credentialsResp .Id != "" {
362+ credentialId = credentialsResp .Id
363363 } else {
364364 return fmt .Errorf ("credentials id not present" )
365365 }
@@ -385,51 +385,50 @@ func mapFields(ctx context.Context, credentialsResp *rabbitmq.CredentialsRespons
385385 model .Hosts = types .ListNull (types .StringType )
386386 model .Uris = types .ListNull (types .StringType )
387387 model .HttpAPIURIs = types .ListNull (types .StringType )
388- if credentials != nil {
389- if credentials .Hosts != nil {
390- respHosts := * credentials .Hosts
391- reconciledHosts := utils .ReconcileStringSlices (modelHosts , respHosts )
388+ if credentials .Hosts != nil {
389+ respHosts := credentials .Hosts
390+ reconciledHosts := utils .ReconcileStringSlices (modelHosts , respHosts )
392391
393- hostsTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHosts )
394- if diags .HasError () {
395- return fmt .Errorf ("failed to map hosts: %w" , core .DiagsToError (diags ))
396- }
397-
398- model .Hosts = hostsTF
392+ hostsTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHosts )
393+ if diags .HasError () {
394+ return fmt .Errorf ("failed to map hosts: %w" , core .DiagsToError (diags ))
399395 }
400- model .Host = types .StringPointerValue (credentials .Host )
401- if credentials .HttpApiUris != nil {
402- respHttpApiUris := * credentials .HttpApiUris
403396
404- reconciledHttpApiUris := utils .ReconcileStringSlices (modelHttpApiUris , respHttpApiUris )
397+ model .Hosts = hostsTF
398+ }
399+ model .Host = types .StringValue (credentials .Host )
400+ if credentials .HttpApiUris != nil {
401+ respHttpApiUris := credentials .HttpApiUris
405402
406- httpApiUrisTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHttpApiUris )
407- if diags .HasError () {
408- return fmt .Errorf ("failed to map httpApiUris: %w" , core .DiagsToError (diags ))
409- }
403+ reconciledHttpApiUris := utils .ReconcileStringSlices (modelHttpApiUris , respHttpApiUris )
410404
411- model .HttpAPIURIs = httpApiUrisTF
405+ httpApiUrisTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHttpApiUris )
406+ if diags .HasError () {
407+ return fmt .Errorf ("failed to map httpApiUris: %w" , core .DiagsToError (diags ))
412408 }
413409
414- if credentials . Uris != nil {
415- respUris := * credentials . Uris
410+ model . HttpAPIURIs = httpApiUrisTF
411+ }
416412
417- reconciledUris := utils .ReconcileStringSlices (modelUris , respUris )
413+ if credentials .Uris != nil {
414+ respUris := credentials .Uris
418415
419- urisTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledUris )
420- if diags .HasError () {
421- return fmt .Errorf ("failed to map uris: %w" , core .DiagsToError (diags ))
422- }
416+ reconciledUris := utils .ReconcileStringSlices (modelUris , respUris )
423417
424- model .Uris = urisTF
418+ urisTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledUris )
419+ if diags .HasError () {
420+ return fmt .Errorf ("failed to map uris: %w" , core .DiagsToError (diags ))
425421 }
426422
427- model .HttpAPIURI = types .StringPointerValue (credentials .HttpApiUri )
428- model .Management = types .StringPointerValue (credentials .Management )
429- model .Password = types .StringPointerValue (credentials .Password )
430- model .Port = types .Int64PointerValue (credentials .Port )
431- model .Uri = types .StringPointerValue (credentials .Uri )
432- model .Username = types .StringPointerValue (credentials .Username )
423+ model .Uris = urisTF
433424 }
425+
426+ model .HttpAPIURI = types .StringPointerValue (credentials .HttpApiUri )
427+ model .Management = types .StringPointerValue (credentials .Management )
428+ model .Password = types .StringValue (credentials .Password )
429+ model .Port = types .Int32PointerValue (credentials .Port )
430+ model .Uri = types .StringPointerValue (credentials .Uri )
431+ model .Username = types .StringValue (credentials .Username )
432+
434433 return nil
435434}
0 commit comments