Skip to content

Commit

Permalink
Support auto creation of missing benchmark resources (SSPROD-12557) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Qiu authored Apr 20, 2022
1 parent 92c8a32 commit f43ca1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sysdig/resource_sysdig_secure_benchmark_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sysdig
import (
"context"
"strconv"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -95,6 +96,9 @@ func resourceSysdigSecureBenchmarkTaskRead(ctx context.Context, d *schema.Resour
benchmarkTask, err := client.GetBenchmarkTask(ctx, d.Id())
if err != nil {
d.SetId("")
if strings.Contains(err.Error(), "404") {
return nil
}
return diag.FromErr(err)
}

Expand All @@ -119,6 +123,9 @@ func resourceSysdigSecureBenchmarkTaskUpdate(ctx context.Context, d *schema.Reso

if err := client.SetBenchmarkTaskEnabled(ctx, d.Id(), enabled); err != nil {
d.SetId("")
if strings.Contains(err.Error(), "404") {
return nil
}
return diag.FromErr(err)
}

Expand All @@ -135,6 +142,10 @@ func resourceSysdigSecureBenchmarkTaskDelete(ctx context.Context, d *schema.Reso

err = client.DeleteBenchmarkTask(ctx, d.Id())
if err != nil {
d.SetId("")
if strings.Contains(err.Error(), "404") {
return nil
}
return diag.FromErr(err)
}
return nil
Expand Down
10 changes: 10 additions & 0 deletions sysdig/resource_sysdig_secure_cloud_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sysdig

import (
"context"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -93,6 +94,9 @@ func resourceSysdigSecureCloudAccountRead(ctx context.Context, d *schema.Resourc
cloudAccount, err := client.GetCloudAccountById(ctx, d.Id())
if err != nil {
d.SetId("")
if strings.Contains(err.Error(), "404") {
return nil
}
return diag.FromErr(err)
}

Expand All @@ -114,6 +118,9 @@ func resourceSysdigSecureCloudAccountUpdate(ctx context.Context, d *schema.Resou

_, err = client.UpdateCloudAccount(ctx, d.Id(), cloudAccountFromResourceData(d))
if err != nil {
if strings.Contains(err.Error(), "404") {
return nil
}
return diag.FromErr(err)
}

Expand All @@ -128,6 +135,9 @@ func resourceSysdigSecureCloudAccountDelete(ctx context.Context, d *schema.Resou

err = client.DeleteCloudAccount(ctx, d.Id())
if err != nil {
if strings.Contains(err.Error(), "404") {
return nil
}
return diag.FromErr(err)
}
return nil
Expand Down

0 comments on commit f43ca1e

Please sign in to comment.