Skip to content

Commit

Permalink
chore(waf): add checkDeleted logic to the rule resource delete functi…
Browse files Browse the repository at this point in the history
…on (#5402)
  • Loading branch information
ruwenqiang123 authored Aug 20, 2024
1 parent 822f331 commit 51d2539
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func resourceRuleRead(_ context.Context, d *schema.ResourceData, meta interface{

getResp, err := client.Request("GET", getPath, &getOpt)
if err != nil {
// If the information leakage prevention rule does not exist, the response HTTP status code of
// the details API is 404.
return common.CheckDeletedDiag(d, err, "error retrieving WAF information leakage prevention rule")
}

Expand Down Expand Up @@ -253,7 +255,9 @@ func resourceRuleDelete(_ context.Context, d *schema.ResourceData, meta interfac

_, err = client.Request("DELETE", deletePath, &deleteOpt)
if err != nil {
return diag.Errorf("error deleting WAF information leakage prevention rule: %s", err)
// If the information leakage prevention rule does not exist, the response HTTP status code of
// the deletion API is 404.
return common.CheckDeletedDiag(d, err, "error deleting WAF information leakage prevention rule")
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func resourceRuleKnownAttackRead(_ context.Context, d *schema.ResourceData, meta

getResp, err := client.Request("GET", getPath, &getOpt)
if err != nil {
// If the known attack source rule does not exist, the response HTTP status code of the details API is 404.
return common.CheckDeletedDiag(d, err, "error retrieving WAF known attack source rule")
}

Expand Down Expand Up @@ -232,7 +233,8 @@ func resourceRuleKnownAttackDelete(_ context.Context, d *schema.ResourceData, me

_, err = client.Request("DELETE", deletePath, &deleteRuleKnownAttackOpt)
if err != nil {
return diag.Errorf("error deleting WAF known attack source rule: %s", err)
// If the known attack source rule does not exist, the response HTTP status code of the deletion API is 404.
return common.CheckDeletedDiag(d, err, "error deleting WAF known attack source rule")
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ func resourceRulePreciseProtectionRead(_ context.Context, d *schema.ResourceData
getRuleResp, err := preciseProtectionClient.Request("GET", getRulePath, &getRuleOpt)

if err != nil {
// If the rule does not exist, the response HTTP status code of the details API is 404.
return common.CheckDeletedDiag(d, err, "error retrieving RulePreciseProtection")
}

Expand Down Expand Up @@ -497,7 +498,8 @@ func resourceRulePreciseProtectionDelete(_ context.Context, d *schema.ResourceDa
}
_, err = preciseProtectionClient.Request("DELETE", deletePath, &deleteOpt)
if err != nil {
return diag.Errorf("error deleting RulePreciseProtection: %s", err)
// If the rule does not exist, the response HTTP status code of the deletion API is 404.
return common.CheckDeletedDiag(d, err, "error deleting RulePreciseProtection")
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func resourceWafRuleWebTamperProtectionRead(_ context.Context, d *schema.Resourc
epsID := cfg.GetEnterpriseProjectID(d)
n, err := rules.GetWithEpsID(wafClient, policyID, d.Id(), epsID).Extract()
if err != nil {
// If the web tamper protection rule does not exist, the response HTTP status code of the details API is 404.
return common.CheckDeletedDiag(d, err, "error retrieving WAF web tamper protection rule")
}

Expand All @@ -156,7 +157,8 @@ func resourceWafRuleWebTamperProtectionDelete(_ context.Context, d *schema.Resou
epsID := cfg.GetEnterpriseProjectID(d)
err = rules.DeleteWithEpsID(wafClient, policyID, d.Id(), epsID).ExtractErr()
if err != nil {
return diag.Errorf("error deleting WAF web tamper protection rule: %s", err)
// If the web tamper protection rule does not exist, the response HTTP status code of the deletion API is 404.
return common.CheckDeletedDiag(d, err, "error deleting WAF web tamper protection rule")
}
return nil
}

0 comments on commit 51d2539

Please sign in to comment.