@@ -22,8 +22,9 @@ 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/logme"
26- "github.com/stackitcloud/stackit-sdk-go/services/logme/wait"
25+
26+ logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api"
27+ "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api/wait"
2728)
2829
2930// Ensure the implementation satisfies the expected interfaces.
@@ -40,7 +41,7 @@ type Model struct {
4041 ProjectId types.String `tfsdk:"project_id"`
4142 Host types.String `tfsdk:"host"`
4243 Password types.String `tfsdk:"password"`
43- Port types.Int64 `tfsdk:"port"`
44+ Port types.Int32 `tfsdk:"port"`
4445 Uri types.String `tfsdk:"uri"`
4546 Username types.String `tfsdk:"username"`
4647}
@@ -52,7 +53,7 @@ func NewCredentialResource() resource.Resource {
5253
5354// credentialResource is the resource implementation.
5455type credentialResource struct {
55- client * logme .APIClient
56+ client * logmeSdk .APIClient
5657}
5758
5859// Metadata returns the resource type name.
@@ -137,7 +138,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest,
137138 Computed : true ,
138139 Sensitive : true ,
139140 },
140- "port" : schema.Int64Attribute {
141+ "port" : schema.Int32Attribute {
141142 Computed : true ,
142143 },
143144 "uri" : schema.StringAttribute {
@@ -168,19 +169,15 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
168169 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
169170
170171 // Create new recordset
171- credentialsResp , err := r .client .CreateCredentials (ctx , projectId , instanceId ).Execute ()
172+ credentialsResp , err := r .client .DefaultAPI . CreateCredentials (ctx , projectId , instanceId ).Execute ()
172173 if err != nil {
173174 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Calling API: %v" , err ))
174175 return
175176 }
176177
177178 ctx = core .LogResponse (ctx )
178179
179- if credentialsResp .Id == nil {
180- core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , "Got empty credential id" )
181- return
182- }
183- credentialId := * credentialsResp .Id
180+ credentialId := credentialsResp .Id
184181 // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
185182 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
186183 "project_id" : projectId ,
@@ -191,7 +188,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
191188 return
192189 }
193190
194- waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
191+ waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
195192 if err != nil {
196193 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Instance creation waiting: %v" , err ))
197194 return
@@ -229,7 +226,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
229226 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
230227 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
231228
232- recordSetResp , err := r .client .GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
229+ recordSetResp , err := r .client .DefaultAPI . GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
233230 if err != nil {
234231 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
235232 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -283,14 +280,14 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
283280 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
284281
285282 // Delete existing record set
286- err := r .client .DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
283+ err := r .client .DefaultAPI . DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
287284 if err != nil {
288285 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Calling API: %v" , err ))
289286 }
290287
291288 ctx = core .LogResponse (ctx )
292289
293- _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
290+ _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
294291 if err != nil {
295292 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
296293 return
@@ -318,7 +315,7 @@ func (r *credentialResource) ImportState(ctx context.Context, req resource.Impor
318315 tflog .Info (ctx , "LogMe credential state imported" )
319316}
320317
321- func mapFields (credentialsResp * logme .CredentialsResponse , model * Model ) error {
318+ func mapFields (credentialsResp * logmeSdk .CredentialsResponse , model * Model ) error {
322319 if credentialsResp == nil {
323320 return fmt .Errorf ("response input is nil" )
324321 }
@@ -333,20 +330,19 @@ func mapFields(credentialsResp *logme.CredentialsResponse, model *Model) error {
333330 var credentialId string
334331 if model .CredentialId .ValueString () != "" {
335332 credentialId = model .CredentialId .ValueString ()
336- } else if credentialsResp .Id != nil {
337- credentialId = * credentialsResp .Id
333+ } else if credentialsResp .Id != "" {
334+ credentialId = credentialsResp .Id
338335 } else {
339336 return fmt .Errorf ("credentials id not present" )
340337 }
341338
342339 model .Id = utils .BuildInternalTerraformId (model .ProjectId .ValueString (), model .InstanceId .ValueString (), credentialId )
343340 model .CredentialId = types .StringValue (credentialId )
344- if credentials != nil {
345- model .Host = types .StringPointerValue (credentials .Host )
346- model .Password = types .StringPointerValue (credentials .Password )
347- model .Port = types .Int64PointerValue (credentials .Port )
348- model .Uri = types .StringPointerValue (credentials .Uri )
349- model .Username = types .StringPointerValue (credentials .Username )
350- }
341+ model .Host = types .StringValue (credentials .Host )
342+ model .Password = types .StringValue (credentials .Password )
343+ model .Port = types .Int32PointerValue (credentials .Port )
344+ model .Uri = types .StringPointerValue (credentials .Uri )
345+ model .Username = types .StringValue (credentials .Username )
346+
351347 return nil
352348}
0 commit comments