Skip to content

Commit

Permalink
Introduce SBFM ruleset warning deprecation message
Browse files Browse the repository at this point in the history
  • Loading branch information
Curtis Lowder committed Apr 17, 2023
1 parent 1bd50b6 commit c197ac8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/2382.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:note
resource/cloudflare_ruleset: introduced future deprecation warning for the `http_request_sbfm` phase.
```
2 changes: 1 addition & 1 deletion docs/resources/ruleset.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ resource "cloudflare_ruleset" "http_config_rules_example" {

- `kind` (String) Type of Ruleset to create. Available values: `custom`, `managed`, `root`, `schema`, `zone`.
- `name` (String) Name of the ruleset.
- `phase` (String) Point in the request/response lifecycle where the ruleset will be created. Available values: `ddos_l4`, `ddos_l7`, `http_custom_errors`, `http_log_custom_fields`, `http_request_cache_settings`, `http_request_firewall_custom`, `http_request_firewall_managed`, `http_request_late_transform`, `http_request_late_transform_managed`, `http_request_main`, `http_request_origin`, `http_request_dynamic_redirect`, `http_request_redirect`, `http_request_sanitize`, `http_request_transform`, `http_response_firewall_managed`, `http_response_headers_transform`, `http_response_headers_transform_managed`, `magic_transit`, `http_ratelimit`, `http_request_sbfm`, `http_config_settings`.
- `phases` (Set of String) Point in the request/response lifecycle where the ruleset will be created. Available values: `ddos_l4`, `ddos_l7`, `http_custom_errors`, `http_log_custom_fields`, `http_request_cache_settings`, `http_request_firewall_custom`, `http_request_firewall_managed`, `http_request_late_transform`, `http_request_late_transform_managed`, `http_request_main`, `http_request_origin`, `http_request_dynamic_redirect`, `http_request_redirect`, `http_request_sanitize`, `http_request_transform`, `http_response_firewall_managed`, `http_response_headers_transform`, `http_response_headers_transform_managed`, `magic_transit`, `http_ratelimit`, `http_request_sbfm`, `http_config_settings`.

### Optional

Expand Down
30 changes: 30 additions & 0 deletions internal/framework/service/rulesets/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (r *RulesetResource) Schema(ctx context.Context, req resource.SchemaRequest
Required: true,
Validators: []validator.String{
stringvalidator.OneOfCaseInsensitive(cloudflare.RulesetPhaseValues()...),
sbfmDepricationWarningValidator{},
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
Expand Down Expand Up @@ -931,3 +932,32 @@ func (r *RulesetResource) Schema(ctx context.Context, req resource.SchemaRequest
},
}
}

type sbfmDepricationWarningValidator struct{}

func (v sbfmDepricationWarningValidator) Description(ctx context.Context) string {
return fmt.Sprintf("Cloudflare is going to change the way Super Bot Fight Mode managed rules are configured through Terraform and our API. No action is required at this time. " +
" Please follow updates to our documentation regarding this here: https://developers.cloudflare.com/bots/get-started/biz-and-ent/#ruleset-engine")
}

func (v sbfmDepricationWarningValidator) MarkdownDescription(ctx context.Context) string {
return fmt.Sprintf("Cloudflare is going to change the way Super Bot Fight Mode managed rules are configured through Terraform and our API. **No action is required at this time**. " +
" Please follow updates to our documentation regarding this [here](https://developers.cloudflare.com/bots/get-started/biz-and-ent/#ruleset-engine)")
}

func (v sbfmDepricationWarningValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
// If the value is unknown or null, there is nothing to validate.
if req.ConfigValue.IsUnknown() || req.ConfigValue.IsNull() {
return
}

if req.ConfigValue.ValueString() == "http_request_sbfm" {
resp.Diagnostics.AddAttributeWarning(
req.Path,
"'http_request_sbfm' may soon become deprecated in the 'cloudflare_ruleset' resource",
v.Description(ctx),
)

return
}
}

0 comments on commit c197ac8

Please sign in to comment.