Skip to content

Commit

Permalink
chore(cts): remove CheckDeleted from CTS data source and add CheckDel…
Browse files Browse the repository at this point in the history
…eted to resource deletion (#5326)
  • Loading branch information
profoundwu authored Aug 5, 2024
1 parent 2bdcbed commit bb90873
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

cts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/model"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/common"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)
Expand Down Expand Up @@ -192,7 +191,7 @@ func dataSourceNotificationsRead(_ context.Context, d *schema.ResourceData, meta

response, err := ctsClient.ListNotifications(listOpts)
if err != nil {
return common.CheckDeletedDiag(d, err, "error retrieving CTS key event notification")
return diag.Errorf("error retrieving CTS key event notification: %s", err)
}
randUUID, err := uuid.GenerateUUID()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,10 @@ func resourceCTSDataTrackerDelete(_ context.Context, d *schema.ResourceData, met

_, err = ctsClient.DeleteTracker(&deleteOpts)
if err != nil {
return diag.Errorf("error deleting CTS data tracker %s: %s", trackerName, err)
return common.CheckDeletedDiag(d,
convertExpected403ErrInto404Err(err, "CTS.0013"),
fmt.Sprintf("error deleting CTS data tracker %s", trackerName),
)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func resourceCTSNotificationDelete(_ context.Context, d *schema.ResourceData, me

_, err = ctsClient.DeleteNotification(&deleteOpts)
if err != nil {
return diag.Errorf("error deleting CTS key events notification: %s", err)
return common.CheckDeletedDiag(d, err, "error deleting CTS key events notification")
}

return nil
Expand Down
11 changes: 10 additions & 1 deletion huaweicloud/services/cts/resource_huaweicloud_cts_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func resourceCTSTrackerDelete(_ context.Context, d *schema.ResourceData, meta in

_, err = ctsClient.DeleteTracker(&deleteOpts)
if err != nil {
return diag.Errorf("error deleting CTS system tracker %s: %s", trackerName, err)
return common.CheckDeletedDiag(d, convertExpected403ErrInto404Err(err, "CTS.0013"), "error deleting CTS system tracker")
}
return nil
}
Expand Down Expand Up @@ -534,3 +534,12 @@ func updateSystemTrackerStatus(c *client.CtsClient, status string) error {
_, err := c.UpdateTracker(&statusReq)
return err
}

func convertExpected403ErrInto404Err(err error, errCode string) error {
if responseErr, ok := err.(*sdkerr.ServiceResponseError); ok {
if responseErr.StatusCode == http.StatusForbidden && responseErr.ErrorCode == errCode {
return golangsdk.ErrDefault404{}
}
}
return err
}

0 comments on commit bb90873

Please sign in to comment.