@@ -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/mariadb"
25- "github.com/stackitcloud/stackit-sdk-go/services/mariadb/wait"
24+ mariadb "github.com/stackitcloud/stackit-sdk-go/services/mariadb/v1api "
25+ "github.com/stackitcloud/stackit-sdk-go/services/mariadb/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 Name types.String `tfsdk:"name"`
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}
@@ -145,7 +145,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest,
145145 Computed : true ,
146146 Sensitive : true ,
147147 },
148- "port" : schema.Int64Attribute {
148+ "port" : schema.Int32Attribute {
149149 Computed : true ,
150150 },
151151 "uri" : schema.StringAttribute {
@@ -176,19 +176,15 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
176176 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
177177
178178 // Create new recordset
179- credentialsResp , err := r .client .CreateCredentials (ctx , projectId , instanceId ).Execute ()
179+ credentialsResp , err := r .client .DefaultAPI . CreateCredentials (ctx , projectId , instanceId ).Execute ()
180180 if err != nil {
181181 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Calling API: %v" , err ))
182182 return
183183 }
184184
185185 ctx = core .LogResponse (ctx )
186186
187- if credentialsResp .Id == nil {
188- core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , "Got empty credential id" )
189- return
190- }
191- credentialId := * credentialsResp .Id
187+ credentialId := credentialsResp .Id
192188 // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
193189 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
194190 "project_id" : projectId ,
@@ -199,7 +195,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
199195 return
200196 }
201197
202- waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
198+ waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
203199 if err != nil {
204200 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Instance creation waiting: %v" , err ))
205201 return
@@ -237,7 +233,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
237233 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
238234 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
239235
240- recordSetResp , err := r .client .GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
236+ recordSetResp , err := r .client .DefaultAPI . GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
241237 if err != nil {
242238 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
243239 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -291,14 +287,14 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
291287 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
292288
293289 // Delete existing record set
294- err := r .client .DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
290+ err := r .client .DefaultAPI . DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
295291 if err != nil {
296292 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Calling API: %v" , err ))
297293 }
298294
299295 ctx = core .LogResponse (ctx )
300296
301- _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
297+ _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
302298 if err != nil {
303299 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
304300 return
@@ -341,8 +337,8 @@ func mapFields(ctx context.Context, credentialsResp *mariadb.CredentialsResponse
341337 var credentialId string
342338 if model .CredentialId .ValueString () != "" {
343339 credentialId = model .CredentialId .ValueString ()
344- } else if credentialsResp .Id != nil {
345- credentialId = * credentialsResp .Id
340+ } else if credentialsResp .Id != "" {
341+ credentialId = credentialsResp .Id
346342 } else {
347343 return fmt .Errorf ("credentials id not present" )
348344 }
@@ -360,25 +356,25 @@ func mapFields(ctx context.Context, credentialsResp *mariadb.CredentialsResponse
360356
361357 model .Hosts = types .ListNull (types .StringType )
362358 model .CredentialId = types .StringValue (credentialId )
363- if credentials != nil {
364- if credentials .Hosts != nil {
365- respHosts := * credentials .Hosts
366359
367- reconciledHosts := utils .ReconcileStringSlices (modelHosts , respHosts )
360+ if credentials .Hosts != nil {
361+ respHosts := credentials .Hosts
368362
369- hostsTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHosts )
370- if diags .HasError () {
371- return fmt .Errorf ("failed to map hosts: %w" , core .DiagsToError (diags ))
372- }
363+ reconciledHosts := utils .ReconcileStringSlices (modelHosts , respHosts )
373364
374- model .Hosts = hostsTF
365+ hostsTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHosts )
366+ if diags .HasError () {
367+ return fmt .Errorf ("failed to map hosts: %w" , core .DiagsToError (diags ))
375368 }
376- model .Host = types .StringPointerValue (credentials .Host )
377- model .Name = types .StringPointerValue (credentials .Name )
378- model .Password = types .StringPointerValue (credentials .Password )
379- model .Port = types .Int64PointerValue (credentials .Port )
380- model .Uri = types .StringPointerValue (credentials .Uri )
381- model .Username = types .StringPointerValue (credentials .Username )
369+
370+ model .Hosts = hostsTF
382371 }
372+ model .Host = types .StringValue (credentials .Host )
373+ model .Name = types .StringPointerValue (credentials .Name )
374+ model .Password = types .StringValue (credentials .Password )
375+ model .Port = types .Int32PointerValue (credentials .Port )
376+ model .Uri = types .StringPointerValue (credentials .Uri )
377+ model .Username = types .StringValue (credentials .Username )
378+
383379 return nil
384380}
0 commit comments