@@ -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/opensearch"
26- "github.com/stackitcloud/stackit-sdk-go/services/opensearch/wait"
25+ opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api "
26+ "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api/ wait"
2727)
2828
2929// Ensure the implementation satisfies the expected interfaces.
@@ -41,7 +41,7 @@ type Model struct {
4141 Host types.String `tfsdk:"host"`
4242 Hosts types.List `tfsdk:"hosts"`
4343 Password types.String `tfsdk:"password"`
44- Port types.Int64 `tfsdk:"port"`
44+ Port types.Int32 `tfsdk:"port"`
4545 Scheme types.String `tfsdk:"scheme"`
4646 Uri types.String `tfsdk:"uri"`
4747 Username types.String `tfsdk:"username"`
@@ -143,7 +143,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest,
143143 Computed : true ,
144144 Sensitive : true ,
145145 },
146- "port" : schema.Int64Attribute {
146+ "port" : schema.Int32Attribute {
147147 Computed : true ,
148148 },
149149 "scheme" : schema.StringAttribute {
@@ -177,26 +177,22 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
177177 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
178178
179179 // Create new recordset
180- credentialsResp , err := r .client .CreateCredentials (ctx , projectId , instanceId ).Execute ()
180+ credentialsResp , err := r .client .DefaultAPI . CreateCredentials (ctx , projectId , instanceId ).Execute ()
181181 if err != nil {
182182 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Calling API: %v" , err ))
183183 return
184184 }
185185
186186 ctx = core .LogResponse (ctx )
187187
188- if credentialsResp .Id == nil {
189- core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , "Got empty credential id" )
190- return
191- }
192- credentialId := * credentialsResp .Id
188+ credentialId := credentialsResp .Id
193189 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
194190 "project_id" : projectId ,
195191 "instance_id" : instanceId ,
196192 "credential_id" : credentialId ,
197193 })
198194
199- waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
195+ waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
200196 if err != nil {
201197 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Instance creation waiting: %v" , err ))
202198 return
@@ -234,7 +230,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
234230 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
235231 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
236232
237- recordSetResp , err := r .client .GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
233+ recordSetResp , err := r .client .DefaultAPI . GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
238234 if err != nil {
239235 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
240236 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -288,14 +284,14 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
288284 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
289285
290286 // Delete existing record set
291- err := r .client .DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
287+ err := r .client .DefaultAPI . DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
292288 if err != nil {
293289 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Calling API: %v" , err ))
294290 }
295291
296292 ctx = core .LogResponse (ctx )
297293
298- _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
294+ _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
299295 if err != nil {
300296 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
301297 return
@@ -338,10 +334,8 @@ func mapFields(ctx context.Context, credentialsResp *opensearch.CredentialsRespo
338334 var credentialId string
339335 if model .CredentialId .ValueString () != "" {
340336 credentialId = model .CredentialId .ValueString ()
341- } else if credentialsResp .Id != nil {
342- credentialId = * credentialsResp .Id
343337 } else {
344- return fmt . Errorf ( "credentials id not present" )
338+ credentialId = credentialsResp . Id
345339 }
346340
347341 model .Id = utils .BuildInternalTerraformId (
@@ -355,24 +349,22 @@ func mapFields(ctx context.Context, credentialsResp *opensearch.CredentialsRespo
355349
356350 model .CredentialId = types .StringValue (credentialId )
357351 model .Hosts = types .ListNull (types .StringType )
358- if credentials != nil {
359- if credentials .Hosts != nil {
360- respHosts := * credentials .Hosts
361- reconciledHosts := utils .ReconcileStringSlices (modelHosts , respHosts )
352+ if credentials .Hosts != nil {
353+ respHosts := credentials .Hosts
354+ reconciledHosts := utils .ReconcileStringSlices (modelHosts , respHosts )
362355
363- hostsTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHosts )
364- if diags .HasError () {
365- return fmt .Errorf ("failed to map hosts: %w" , core .DiagsToError (diags ))
366- }
367-
368- model .Hosts = hostsTF
356+ hostsTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledHosts )
357+ if diags .HasError () {
358+ return fmt .Errorf ("failed to map hosts: %w" , core .DiagsToError (diags ))
369359 }
370- model .Host = types .StringPointerValue (credentials .Host )
371- model .Password = types .StringPointerValue (credentials .Password )
372- model .Port = types .Int64PointerValue (credentials .Port )
373- model .Scheme = types .StringPointerValue (credentials .Scheme )
374- model .Uri = types .StringPointerValue (credentials .Uri )
375- model .Username = types .StringPointerValue (credentials .Username )
360+
361+ model .Hosts = hostsTF
376362 }
363+ model .Host = types .StringValue (credentials .Host )
364+ model .Password = types .StringValue (credentials .Password )
365+ model .Port = types .Int32PointerValue (credentials .Port )
366+ model .Scheme = types .StringPointerValue (credentials .Scheme )
367+ model .Uri = types .StringPointerValue (credentials .Uri )
368+ model .Username = types .StringValue (credentials .Username )
377369 return nil
378370}
0 commit comments