@@ -22,8 +22,10 @@ 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+ "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api/wait"
27+
28+ logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api"
2729)
2830
2931// Ensure the implementation satisfies the expected interfaces.
@@ -40,7 +42,7 @@ type Model struct {
4042 ProjectId types.String `tfsdk:"project_id"`
4143 Host types.String `tfsdk:"host"`
4244 Password types.String `tfsdk:"password"`
43- Port types.Int64 `tfsdk:"port"`
45+ Port types.Int32 `tfsdk:"port"`
4446 Uri types.String `tfsdk:"uri"`
4547 Username types.String `tfsdk:"username"`
4648}
@@ -52,7 +54,7 @@ func NewCredentialResource() resource.Resource {
5254
5355// credentialResource is the resource implementation.
5456type credentialResource struct {
55- client * logme .APIClient
57+ client * logmeSdk .APIClient
5658}
5759
5860// Metadata returns the resource type name.
@@ -137,7 +139,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest,
137139 Computed : true ,
138140 Sensitive : true ,
139141 },
140- "port" : schema.Int64Attribute {
142+ "port" : schema.Int32Attribute {
141143 Computed : true ,
142144 },
143145 "uri" : schema.StringAttribute {
@@ -168,19 +170,19 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
168170 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
169171
170172 // Create new recordset
171- credentialsResp , err := r .client .CreateCredentials (ctx , projectId , instanceId ).Execute ()
173+ credentialsResp , err := r .client .DefaultAPI . CreateCredentials (ctx , projectId , instanceId ).Execute ()
172174 if err != nil {
173175 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Calling API: %v" , err ))
174176 return
175177 }
176178
177179 ctx = core .LogResponse (ctx )
178180
179- if credentialsResp . Id == nil {
180- core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , "Got empty credential id " )
181+ if credentialsResp == nil {
182+ core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , "Got empty credential response " )
181183 return
182184 }
183- credentialId := * credentialsResp .Id
185+ credentialId := credentialsResp .Id
184186 // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
185187 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
186188 "project_id" : projectId ,
@@ -191,7 +193,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
191193 return
192194 }
193195
194- waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
196+ waitResp , err := wait .CreateCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
195197 if err != nil {
196198 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating credential" , fmt .Sprintf ("Instance creation waiting: %v" , err ))
197199 return
@@ -229,7 +231,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
229231 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
230232 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
231233
232- recordSetResp , err := r .client .GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
234+ recordSetResp , err := r .client .DefaultAPI . GetCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
233235 if err != nil {
234236 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
235237 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -283,14 +285,14 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
283285 ctx = tflog .SetField (ctx , "credential_id" , credentialId )
284286
285287 // Delete existing record set
286- err := r .client .DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
288+ err := r .client .DefaultAPI . DeleteCredentials (ctx , projectId , instanceId , credentialId ).Execute ()
287289 if err != nil {
288290 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Calling API: %v" , err ))
289291 }
290292
291293 ctx = core .LogResponse (ctx )
292294
293- _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client , projectId , instanceId , credentialId ).WaitWithContext (ctx )
295+ _ , err = wait .DeleteCredentialsWaitHandler (ctx , r .client . DefaultAPI , projectId , instanceId , credentialId ).WaitWithContext (ctx )
294296 if err != nil {
295297 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting credential" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
296298 return
@@ -318,7 +320,7 @@ func (r *credentialResource) ImportState(ctx context.Context, req resource.Impor
318320 tflog .Info (ctx , "LogMe credential state imported" )
319321}
320322
321- func mapFields (credentialsResp * logme .CredentialsResponse , model * Model ) error {
323+ func mapFields (credentialsResp * logmeSdk .CredentialsResponse , model * Model ) error {
322324 if credentialsResp == nil {
323325 return fmt .Errorf ("response input is nil" )
324326 }
@@ -333,20 +335,19 @@ func mapFields(credentialsResp *logme.CredentialsResponse, model *Model) error {
333335 var credentialId string
334336 if model .CredentialId .ValueString () != "" {
335337 credentialId = model .CredentialId .ValueString ()
336- } else if credentialsResp .Id != nil {
337- credentialId = * credentialsResp .Id
338+ } else if credentialsResp .Id != "" {
339+ credentialId = credentialsResp .Id
338340 } else {
339341 return fmt .Errorf ("credentials id not present" )
340342 }
341343
342344 model .Id = utils .BuildInternalTerraformId (model .ProjectId .ValueString (), model .InstanceId .ValueString (), credentialId )
343345 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- }
346+ model .Host = types .StringValue (credentials .Host )
347+ model .Password = types .StringValue (credentials .Password )
348+ model .Port = types .Int32PointerValue (credentials .Port )
349+ model .Uri = types .StringPointerValue (credentials .Uri )
350+ model .Username = types .StringValue (credentials .Username )
351+
351352 return nil
352353}
0 commit comments