Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(waf): add checkDeleted logic to the rule resource delete function #5402

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading