@@ -26,7 +26,7 @@ import (
2626 "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2727 "github.com/hashicorp/terraform-plugin-framework/types"
2828 "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
29- "github.com/stackitcloud/stackit-sdk-go/services/secretsmanager"
29+ secretsmanager "github.com/stackitcloud/stackit-sdk-go/services/secretsmanager/v1api "
3030)
3131
3232// Ensure the implementation satisfies the expected interfaces.
@@ -204,19 +204,19 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
204204 return
205205 }
206206 // Create new instance
207- createResp , err := r .client .CreateInstance (ctx , projectId ).CreateInstancePayload (* payload ).Execute ()
207+ createResp , err := r .client .DefaultAPI . CreateInstance (ctx , projectId ).CreateInstancePayload (* payload ).Execute ()
208208 if err != nil {
209209 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Calling API: %v" , err ))
210210 return
211211 }
212212
213213 ctx = core .LogResponse (ctx )
214214
215- if createResp .Id == nil {
215+ if createResp .Id == "" {
216216 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , "Got empty instance id" )
217217 return
218218 }
219- instanceId := * createResp .Id
219+ instanceId := createResp .Id
220220 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
221221 "project_id" : projectId ,
222222 "instance_id" : instanceId ,
@@ -228,7 +228,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
228228 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Creating ACLs: %v" , err ))
229229 return
230230 }
231- aclList , err := r .client .ListACLs (ctx , projectId , instanceId ).Execute ()
231+ aclList , err := r .client .DefaultAPI . ListACLs (ctx , projectId , instanceId ).Execute ()
232232 if err != nil {
233233 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Calling API for ACLs data: %v" , err ))
234234 return
@@ -266,7 +266,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
266266 ctx = tflog .SetField (ctx , "project_id" , projectId )
267267 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
268268
269- instanceResp , err := r .client .GetInstance (ctx , projectId , instanceId ).Execute ()
269+ instanceResp , err := r .client .DefaultAPI . GetInstance (ctx , projectId , instanceId ).Execute ()
270270 if err != nil {
271271 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
272272 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -279,7 +279,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
279279
280280 ctx = core .LogResponse (ctx )
281281
282- aclList , err := r .client .ListACLs (ctx , projectId , instanceId ).Execute ()
282+ aclList , err := r .client .DefaultAPI . ListACLs (ctx , projectId , instanceId ).Execute ()
283283 if err != nil {
284284 core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Calling API for ACLs data: %v" , err ))
285285 return
@@ -324,7 +324,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
324324 return
325325 }
326326 // Update instance
327- err = r .client .UpdateInstance (ctx , projectId , instanceId ).UpdateInstancePayload (* payload ).Execute ()
327+ err = r .client .DefaultAPI . UpdateInstance (ctx , projectId , instanceId ).UpdateInstancePayload (* payload ).Execute ()
328328 if err != nil {
329329 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance" , fmt .Sprintf ("Calling API: %v" , err ))
330330 return
@@ -348,15 +348,15 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
348348 return
349349 }
350350
351- instanceResp , err := r .client .GetInstance (ctx , projectId , instanceId ).Execute ()
351+ instanceResp , err := r .client .DefaultAPI . GetInstance (ctx , projectId , instanceId ).Execute ()
352352 if err != nil {
353353 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance acl" , fmt .Sprintf ("Calling API: %v" , err ))
354354 return
355355 }
356356
357357 ctx = core .LogResponse (ctx )
358358
359- aclList , err := r .client .ListACLs (ctx , projectId , instanceId ).Execute ()
359+ aclList , err := r .client .DefaultAPI . ListACLs (ctx , projectId , instanceId ).Execute ()
360360 if err != nil {
361361 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance" , fmt .Sprintf ("Calling API for ACLs data: %v" , err ))
362362 return
@@ -395,7 +395,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
395395 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
396396
397397 // Delete existing instance
398- err := r .client .DeleteInstance (ctx , projectId , instanceId ).Execute ()
398+ err := r .client .DefaultAPI . DeleteInstance (ctx , projectId , instanceId ).Execute ()
399399 if err != nil {
400400 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting instance" , fmt .Sprintf ("Calling API: %v" , err ))
401401 return
@@ -436,22 +436,22 @@ func mapFields(instance *secretsmanager.Instance, aclList *secretsmanager.ListAC
436436 var instanceId string
437437 if model .InstanceId .ValueString () != "" {
438438 instanceId = model .InstanceId .ValueString ()
439- } else if instance .Id != nil {
440- instanceId = * instance .Id
439+ } else if instance .Id != "" {
440+ instanceId = instance .Id
441441 } else {
442442 return fmt .Errorf ("instance id not present" )
443443 }
444444
445445 model .Id = utils .BuildInternalTerraformId (model .ProjectId .ValueString (), instanceId )
446446 model .InstanceId = types .StringValue (instanceId )
447- model .Name = types .StringPointerValue (instance .Name )
447+ model .Name = types .StringValue (instance .Name )
448448
449449 if instance .KmsKey != nil {
450450 model .KmsKey = & KmsKeyModel {
451- KeyId : types .StringPointerValue (instance .KmsKey .KeyId ),
452- KeyRingId : types .StringPointerValue (instance .KmsKey .KeyRingId ),
453- KeyVersion : types .Int64PointerValue (instance .KmsKey .KeyVersion ),
454- ServiceAccountEmail : types .StringPointerValue (instance .KmsKey .ServiceAccountEmail ),
451+ KeyId : types .StringValue (instance .KmsKey .KeyId ),
452+ KeyRingId : types .StringValue (instance .KmsKey .KeyRingId ),
453+ KeyVersion : types .Int64Value (instance .KmsKey .KeyVersion ),
454+ ServiceAccountEmail : types .StringValue (instance .KmsKey .ServiceAccountEmail ),
455455 }
456456 }
457457
@@ -467,14 +467,14 @@ func mapACLs(aclList *secretsmanager.ListACLsResponse, model *Model) error {
467467 if aclList == nil {
468468 return fmt .Errorf ("nil ACL list" )
469469 }
470- if aclList . Acls == nil || len (* aclList .Acls ) == 0 {
470+ if len (aclList .Acls ) == 0 {
471471 model .ACLs = types .SetNull (types .StringType )
472472 return nil
473473 }
474474
475475 acls := []attr.Value {}
476- for _ , acl := range * aclList .Acls {
477- acls = append (acls , types .StringValue (* acl .Cidr ))
476+ for _ , acl := range aclList .Acls {
477+ acls = append (acls , types .StringValue (acl .Cidr ))
478478 }
479479 aclsList , diags := types .SetValue (types .StringType , acls )
480480 if diags .HasError () {
@@ -489,15 +489,15 @@ func toCreatePayload(model *Model) (*secretsmanager.CreateInstancePayload, error
489489 return nil , fmt .Errorf ("nil model" )
490490 }
491491 payload := & secretsmanager.CreateInstancePayload {
492- Name : conversion . StringValueToPointer ( model .Name ),
492+ Name : model .Name . ValueString ( ),
493493 }
494494
495495 if model .KmsKey != nil {
496496 payload .KmsKey = & secretsmanager.KmsKeyPayload {
497- KeyId : conversion . StringValueToPointer ( model .KmsKey .KeyId ),
498- KeyRingId : conversion . StringValueToPointer ( model .KmsKey .KeyRingId ),
499- KeyVersion : conversion . Int64ValueToPointer ( model .KmsKey .KeyVersion ),
500- ServiceAccountEmail : conversion . StringValueToPointer ( model .KmsKey .ServiceAccountEmail ),
497+ KeyId : model .KmsKey .KeyId . ValueString ( ),
498+ KeyRingId : model .KmsKey .KeyRingId . ValueString ( ),
499+ KeyVersion : model .KmsKey .KeyVersion . ValueInt64 ( ),
500+ ServiceAccountEmail : model .KmsKey .ServiceAccountEmail . ValueString ( ),
501501 }
502502 }
503503
@@ -510,15 +510,15 @@ func toUpdatePayload(model *Model) (*secretsmanager.UpdateInstancePayload, error
510510 }
511511
512512 payload := & secretsmanager.UpdateInstancePayload {
513- Name : conversion . StringValueToPointer ( model .Name ),
513+ Name : model .Name . ValueString ( ),
514514 }
515515
516516 if model .KmsKey != nil {
517517 payload .KmsKey = & secretsmanager.KmsKeyPayload {
518- KeyId : conversion . StringValueToPointer ( model .KmsKey .KeyId ),
519- KeyRingId : conversion . StringValueToPointer ( model .KmsKey .KeyRingId ),
520- KeyVersion : conversion . Int64ValueToPointer ( model .KmsKey .KeyVersion ),
521- ServiceAccountEmail : conversion . StringValueToPointer ( model .KmsKey .ServiceAccountEmail ),
518+ KeyId : model .KmsKey .KeyId . ValueString ( ),
519+ KeyRingId : model .KmsKey .KeyRingId . ValueString ( ),
520+ KeyVersion : model .KmsKey .KeyVersion . ValueInt64 ( ),
521+ ServiceAccountEmail : model .KmsKey .ServiceAccountEmail . ValueString ( ),
522522 }
523523 }
524524
@@ -528,7 +528,7 @@ func toUpdatePayload(model *Model) (*secretsmanager.UpdateInstancePayload, error
528528// updateACLs creates and deletes ACLs so that the instance's ACLs are the ones in the model
529529func updateACLs (ctx context.Context , projectId , instanceId string , acls []string , client * secretsmanager.APIClient ) error {
530530 // Get ACLs current state
531- currentACLsResp , err := client .ListACLs (ctx , projectId , instanceId ).Execute ()
531+ currentACLsResp , err := client .DefaultAPI . ListACLs (ctx , projectId , instanceId ).Execute ()
532532 if err != nil {
533533 return fmt .Errorf ("fetching current ACLs: %w" , err )
534534 }
@@ -544,29 +544,29 @@ func updateACLs(ctx context.Context, projectId, instanceId string, acls []string
544544 isInModel : true ,
545545 }
546546 }
547- for _ , acl := range * currentACLsResp .Acls {
548- cidr := * acl .Cidr
547+ for _ , acl := range currentACLsResp .Acls {
548+ cidr := acl .Cidr
549549 if _ , ok := aclsState [cidr ]; ! ok {
550550 aclsState [cidr ] = & aclState {}
551551 }
552552 aclsState [cidr ].isCreated = true
553- aclsState [cidr ].id = * acl .Id
553+ aclsState [cidr ].id = acl .Id
554554 }
555555
556556 // Create/delete ACLs
557557 for cidr , state := range aclsState {
558558 if state .isInModel && ! state .isCreated {
559559 payload := secretsmanager.CreateACLPayload {
560- Cidr : new ( cidr ) ,
560+ Cidr : cidr ,
561561 }
562- _ , err := client .CreateACL (ctx , projectId , instanceId ).CreateACLPayload (payload ).Execute ()
562+ _ , err := client .DefaultAPI . CreateACL (ctx , projectId , instanceId ).CreateACLPayload (payload ).Execute ()
563563 if err != nil {
564564 return fmt .Errorf ("creating ACL '%v': %w" , cidr , err )
565565 }
566566 }
567567
568568 if ! state .isInModel && state .isCreated {
569- err := client .DeleteACL (ctx , projectId , instanceId , state .id ).Execute ()
569+ err := client .DefaultAPI . DeleteACL (ctx , projectId , instanceId , state .id ).Execute ()
570570 if err != nil {
571571 return fmt .Errorf ("deleting ACL '%v': %w" , cidr , err )
572572 }
0 commit comments