@@ -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/opensearch"
25- "github.com/stackitcloud/stackit-sdk-go/services/opensearch/wait"
24+ opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api "
25+ "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api/ wait"
2626)
2727
2828// Ensure the implementation satisfies the expected interfaces.
@@ -40,7 +40,7 @@ type Model struct {
4040 Host types.String `tfsdk:"host"`
4141 Hosts types.List `tfsdk:"hosts"`
4242 Password types.String `tfsdk:"password"`
43- Port types.Int64 `tfsdk:"port"`
43+ Port types.Int32 `tfsdk:"port"`
4444 Scheme types.String `tfsdk:"scheme"`
4545 Uri types.String `tfsdk:"uri"`
4646 Username types.String `tfsdk:"username"`
@@ -142,7 +142,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest,
142142 Computed : true ,
143143 Sensitive : true ,
144144 },
145- "port" : schema.Int64Attribute {
145+ "port" : schema.Int32Attribute {
146146 Computed : true ,
147147 },
148148 "scheme" : schema.StringAttribute {
@@ -176,26 +176,22 @@ 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 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
193189 "project_id" : projectId ,
194190 "instance_id" : instanceId ,
195191 "credential_id" : credentialId ,
196192 })
197193
198- waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
194+ waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
199195 if err != nil {
200196 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Instance creation waiting: %v" , err ))
201197 return
@@ -233,7 +229,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
233229 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
234230 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
235231
236- recordSetResp , err := r .client .GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
232+ recordSetResp , err := r .client .DefaultAPI . GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
237233 if err != nil {
238234 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
239235 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -287,14 +283,14 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
287283 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
288284
289285 // Delete existing record set
290- err := r .client .DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
286+ err := r .client .DefaultAPI . DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
291287 if err != nil {
292288 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Calling API: %v" , err ))
293289 }
294290
295291 ctx = core .LogResponse (ctx )
296292
297- _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
293+ _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
298294 if err != nil {
299295 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
300296 return
@@ -337,10 +333,8 @@ func mapFields(ctx context.Context, credentialsResp *opensearch.CredentialsRespo
337333 var credentialId string
338334 if model .CredentialId .ValueString () != "" {
339335 credentialId = model .CredentialId .ValueString ()
340- } else if credentialsResp .Id != nil {
341- credentialId = * credentialsResp .Id
342336 } else {
343- return fmt . Errorf ( "credentials id not present" )
337+ credentialId = credentialsResp . Id
344338 }
345339
346340 model .Id = utils .BuildInternalTerraformId (
@@ -354,24 +348,22 @@ func mapFields(ctx context.Context, credentialsResp *opensearch.CredentialsRespo
354348
355349 model .CredentialId = types .StringValue (credentialId )
356350 model .Hosts = types .ListNull (types .StringType )
357- if credentials != nil {
358- if credentials .Hosts != nil {
359- respHosts := * credentials .Hosts
360- reconciledHosts := utils .ReconcileStringSlices (modelHosts , respHosts )
351+ if credentials .Hosts != nil {
352+ respHosts := credentials .Hosts
353+ reconciledHosts := utils .ReconcileStringSlices (modelHosts , respHosts )
361354
362- hostsTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHosts )
363- if diags .HasError () {
364- return fmt .Errorf ("failed to map hosts: %w" , core .DiagsToError (diags ))
365- }
366-
367- model .Hosts = hostsTF
355+ hostsTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHosts )
356+ if diags .HasError () {
357+ return fmt .Errorf ("failed to map hosts: %w" , core .DiagsToError (diags ))
368358 }
369- model .Host = types .StringPointerValue (credentials .Host )
370- model .Password = types .StringPointerValue (credentials .Password )
371- model .Port = types .Int64PointerValue (credentials .Port )
372- model .Scheme = types .StringPointerValue (credentials .Scheme )
373- model .Uri = types .StringPointerValue (credentials .Uri )
374- model .Username = types .StringPointerValue (credentials .Username )
359+
360+ model .Hosts = hostsTF
375361 }
362+ model .Host = types .StringValue (credentials .Host )
363+ model .Password = types .StringValue (credentials .Password )
364+ model .Port = types .Int32PointerValue (credentials .Port )
365+ model .Scheme = types .StringPointerValue (credentials .Scheme )
366+ model .Uri = types .StringPointerValue (credentials .Uri )
367+ model .Username = types .StringValue (credentials .Username )
376368 return nil
377369}
0 commit comments