11package aquasec
22
33import (
4- "context"
54 "fmt"
6- "log"
75 "strings"
86
9- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10-
117 "github.com/aquasecurity/terraform-provider-aquasec/client"
128 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
139)
1410
1511func resourceApplicationScope () * schema.Resource {
1612 return & schema.Resource {
17- CreateContext : resourceApplicationScopeCreate ,
18- ReadContext : resourceApplicationScopeRead ,
19- UpdateContext : resourceApplicationScopeUpdate ,
20- DeleteContext : resourceApplicationScopeDelete ,
13+ Create : resourceApplicationScopeCreate ,
14+ Read : resourceApplicationScopeRead ,
15+ Update : resourceApplicationScopeUpdate ,
16+ Delete : resourceApplicationScopeDelete ,
2117 Importer : & schema.ResourceImporter {
2218 StateContext : schema .ImportStatePassthroughContext ,
2319 },
2420 Schema : map [string ]* schema.Schema {
2521 "name" : {
2622 Type : schema .TypeString ,
27- Description : "You are using a legacy resource. Consider migrating to 'aquasec_application_scope_saas' ." ,
23+ Description : "Name of an application scope ." ,
2824 Required : true ,
2925 ForceNew : true ,
3026 ValidateFunc : func (val interface {}, key string ) ([]string , []error ) {
@@ -382,29 +378,22 @@ func resourceApplicationScope() *schema.Resource {
382378 }
383379}
384380
385- func resourceApplicationScopeCreate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
386- result := isSaasEnv ()
387- log .Printf ("is SAAS envvvvvv %v" , result ) // TODO: DELETE
388- var diags diag.Diagnostics
389- diags = addSaasResourceWarning (diags , "aquasec_application_scope" , "aquasec_application_scope_saas" )
390-
381+ func resourceApplicationScopeCreate (d * schema.ResourceData , m interface {}) error {
391382 ac := m .(* client.Client )
392383 name := d .Get ("name" ).(string )
393384 iap , err1 := expandApplicationScope (d )
394385 if err1 != nil {
395- return diag . FromErr ( fmt .Errorf ("expanding applications failed with error: %w " , err1 ) )
386+ return fmt .Errorf ("expanding applications is failed with error: %v " , err1 )
396387 }
397388 err := ac .CreateApplicationScope (iap )
398389
399390 if err == nil {
400391 d .SetId (name )
401392 } else {
402- return diag . FromErr ( fmt .Errorf ("application scope resource create is failed with error: %w " , err1 ) )
393+ return fmt .Errorf ("application scope resource create is failed with error: %v " , err )
403394 }
404- readDiags := resourceApplicationScopeRead (ctx , d , m )
405- diags = append (diags , readDiags ... )
406395
407- return diags
396+ return resourceApplicationScopeRead ( d , m )
408397}
409398
410399func expandApplicationScope (d * schema.ResourceData ) (* client.ApplicationScope , error ) {
@@ -458,7 +447,7 @@ func expandApplicationScope(d *schema.ResourceData) (*client.ApplicationScope, e
458447
459448}
460449
461- func resourceApplicationScopeRead (ctx context. Context , d * schema.ResourceData , m interface {}) diag. Diagnostics {
450+ func resourceApplicationScopeRead (d * schema.ResourceData , m interface {}) error {
462451 ac := m .(* client.Client )
463452
464453 iap , err := ac .GetApplicationScope (d .Id ())
@@ -467,41 +456,38 @@ func resourceApplicationScopeRead(ctx context.Context, d *schema.ResourceData, m
467456 d .SetId ("" )
468457 return nil
469458 }
470- return diag . FromErr ( err )
459+ return err
471460 }
472461
473462 err = d .Set ("name" , iap .Name )
474463 if err != nil {
475- return diag . FromErr ( err )
464+ return err
476465 }
477466 err = d .Set ("description" , iap .Description )
478467 if err != nil {
479- return diag . FromErr ( err )
468+ return err
480469 }
481470 err = d .Set ("author" , iap .Author )
482471 if err != nil {
483- return diag . FromErr ( err )
472+ return err
484473 }
485474 err = d .Set ("owner_email" , iap .OwnerEmail )
486475 if err != nil {
487- return diag . FromErr ( err )
476+ return err
488477 }
489478
490479 err = d .Set ("categories" , flattenCategories (iap .Categories ))
491480
492481 if err != nil {
493- return diag . FromErr ( err )
482+ return err
494483 }
495484
496485 d .SetId (iap .Name )
497486
498487 return nil
499488}
500489
501- func resourceApplicationScopeUpdate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
502- var diags diag.Diagnostics
503- diags = addSaasResourceWarning (diags , "aquasec_application_scope" , "aquasec_application_scope_saas" )
504-
490+ func resourceApplicationScopeUpdate (d * schema.ResourceData , m interface {}) error {
505491 ac := m .(* client.Client )
506492 name := d .Get ("name" ).(string )
507493
@@ -510,16 +496,16 @@ func resourceApplicationScopeUpdate(ctx context.Context, d *schema.ResourceData,
510496
511497 iap , err1 := expandApplicationScope (d )
512498 if err1 != nil {
513- return diag . FromErr ( err1 )
499+ return err1
514500 }
515501 err = ac .UpdateApplicationScope (iap , name )
516502 if err != nil {
517- return diag . FromErr ( err )
503+ return err
518504 }
519- return resourceApplicationScopeRead (ctx , d , m )
505+ return resourceApplicationScopeRead (d , m )
520506
521507 }
522- return diags
508+ return nil
523509}
524510
525511func createCategory (a map [string ]interface {}, w map [string ]interface {}, i map [string ]interface {}) client.Category {
@@ -635,15 +621,15 @@ func createEmptyCommonStruct() client.CommonStruct {
635621 return commonStruct1
636622}
637623
638- func resourceApplicationScopeDelete (ctx context. Context , d * schema.ResourceData , m interface {}) diag. Diagnostics {
624+ func resourceApplicationScopeDelete (d * schema.ResourceData , m interface {}) error {
639625 ac := m .(* client.Client )
640626 name := d .Get ("name" ).(string )
641627 err := ac .DeleteApplicationScope (name )
642628
643629 if err == nil {
644630 d .SetId ("" )
645631 } else {
646- return diag . FromErr ( err )
632+ return err
647633 }
648634 return nil
649635}
0 commit comments