RateLimit

class RateLimit : KotlinCustomResource

cloudflare.RateLimit is in a deprecation phase until June 15th, 2025. During this time period, this resource is still fully supported but you are strongly advised to move to the cloudflare.Ruleset resource. Full details can be found in the developer documentation.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as cloudflare from "@pulumi/cloudflare";
const exampleRateLimit = new cloudflare.RateLimit("example_rate_limit", {
zoneId: "023e105f4ecef8ad9ca31a8372d0c353",
action: {
mode: "simulate",
response: {
body: "<error>This request has been rate-limited.</error>",
contentType: "text/xml",
},
timeout: 86400,
},
match: {
headers: [{
name: "Cf-Cache-Status",
op: "eq",
value: "HIT",
}],
request: {
methods: [
"GET",
"POST",
],
schemes: [
"HTTP",
"HTTPS",
],
url: "*.example.org/path*",
},
response: {
originTraffic: true,
},
},
period: 900,
threshold: 60,
});
import pulumi
import pulumi_cloudflare as cloudflare
example_rate_limit = cloudflare.RateLimit("example_rate_limit",
zone_id="023e105f4ecef8ad9ca31a8372d0c353",
action={
"mode": "simulate",
"response": {
"body": "<error>This request has been rate-limited.</error>",
"content_type": "text/xml",
},
"timeout": 86400,
},
match={
"headers": [{
"name": "Cf-Cache-Status",
"op": "eq",
"value": "HIT",
}],
"request": {
"methods": [
"GET",
"POST",
],
"schemes": [
"HTTP",
"HTTPS",
],
"url": "*.example.org/path*",
},
"response": {
"origin_traffic": True,
},
},
period=900,
threshold=60)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Cloudflare = Pulumi.Cloudflare;
return await Deployment.RunAsync(() =>
{
var exampleRateLimit = new Cloudflare.RateLimit("example_rate_limit", new()
{
ZoneId = "023e105f4ecef8ad9ca31a8372d0c353",
Action = new Cloudflare.Inputs.RateLimitActionArgs
{
Mode = "simulate",
Response = new Cloudflare.Inputs.RateLimitActionResponseArgs
{
Body = "<error>This request has been rate-limited.</error>",
ContentType = "text/xml",
},
Timeout = 86400,
},
Match = new Cloudflare.Inputs.RateLimitMatchArgs
{
Headers = new[]
{
new Cloudflare.Inputs.RateLimitMatchHeaderArgs
{
Name = "Cf-Cache-Status",
Op = "eq",
Value = "HIT",
},
},
Request = new Cloudflare.Inputs.RateLimitMatchRequestArgs
{
Methods = new[]
{
"GET",
"POST",
},
Schemes = new[]
{
"HTTP",
"HTTPS",
},
Url = "*.example.org/path*",
},
Response = new Cloudflare.Inputs.RateLimitMatchResponseArgs
{
OriginTraffic = true,
},
},
Period = 900,
Threshold = 60,
});
});
package main
import (
"github.com/pulumi/pulumi-cloudflare/sdk/v6/go/cloudflare"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := cloudflare.NewRateLimit(ctx, "example_rate_limit", &cloudflare.RateLimitArgs{
ZoneId: pulumi.String("023e105f4ecef8ad9ca31a8372d0c353"),
Action: &cloudflare.RateLimitActionArgs{
Mode: pulumi.String("simulate"),
Response: &cloudflare.RateLimitActionResponseArgs{
Body: pulumi.String("<error>This request has been rate-limited.</error>"),
ContentType: pulumi.String("text/xml"),
},
Timeout: pulumi.Float64(86400),
},
Match: &cloudflare.RateLimitMatchArgs{
Headers: cloudflare.RateLimitMatchHeaderArray{
&cloudflare.RateLimitMatchHeaderArgs{
Name: pulumi.String("Cf-Cache-Status"),
Op: pulumi.String("eq"),
Value: pulumi.String("HIT"),
},
},
Request: &cloudflare.RateLimitMatchRequestArgs{
Methods: pulumi.StringArray{
pulumi.String("GET"),
pulumi.String("POST"),
},
Schemes: pulumi.StringArray{
pulumi.String("HTTP"),
pulumi.String("HTTPS"),
},
Url: pulumi.String("*.example.org/path*"),
},
Response: &cloudflare.RateLimitMatchResponseArgs{
OriginTraffic: pulumi.Bool(true),
},
},
Period: pulumi.Float64(900),
Threshold: pulumi.Float64(60),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.cloudflare.RateLimit;
import com.pulumi.cloudflare.RateLimitArgs;
import com.pulumi.cloudflare.inputs.RateLimitActionArgs;
import com.pulumi.cloudflare.inputs.RateLimitActionResponseArgs;
import com.pulumi.cloudflare.inputs.RateLimitMatchArgs;
import com.pulumi.cloudflare.inputs.RateLimitMatchRequestArgs;
import com.pulumi.cloudflare.inputs.RateLimitMatchResponseArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var exampleRateLimit = new RateLimit("exampleRateLimit", RateLimitArgs.builder()
.zoneId("023e105f4ecef8ad9ca31a8372d0c353")
.action(RateLimitActionArgs.builder()
.mode("simulate")
.response(RateLimitActionResponseArgs.builder()
.body("<error>This request has been rate-limited.</error>")
.contentType("text/xml")
.build())
.timeout(86400.0)
.build())
.match(RateLimitMatchArgs.builder()
.headers(RateLimitMatchHeaderArgs.builder()
.name("Cf-Cache-Status")
.op("eq")
.value("HIT")
.build())
.request(RateLimitMatchRequestArgs.builder()
.methods(
"GET",
"POST")
.schemes(
"HTTP",
"HTTPS")
.url("*.example.org/path*")
.build())
.response(RateLimitMatchResponseArgs.builder()
.originTraffic(true)
.build())
.build())
.period(900.0)
.threshold(60.0)
.build());
}
}
resources:
exampleRateLimit:
type: cloudflare:RateLimit
name: example_rate_limit
properties:
zoneId: 023e105f4ecef8ad9ca31a8372d0c353
action:
mode: simulate
response:
body: <error>This request has been rate-limited.</error>
contentType: text/xml
timeout: 86400
match:
headers:
- name: Cf-Cache-Status
op: eq
value: HIT
request:
methods:
- GET
- POST
schemes:
- HTTP
- HTTPS
url: '*.example.org/path*'
response:
originTraffic: true
period: 900
threshold: 60

Import

$ pulumi import cloudflare:index/rateLimit:RateLimit example '<zone_id>/<rate_limit_id>'

Properties

Link copied to clipboard
val action: Output<RateLimitAction>

The action to perform when the threshold of matched traffic within the configured period is exceeded.

Link copied to clipboard

Criteria specifying when the current rate limit should be bypassed. You can specify that the rate limit should not apply to one or more URLs.

Link copied to clipboard
val description: Output<String>

An informative summary of the rate limit. This value is sanitized and any tags will be removed.

Link copied to clipboard
val disabled: Output<Boolean>

When true, indicates that the rate limit is currently disabled.

Link copied to clipboard
val id: Output<String>
Link copied to clipboard
val match: Output<RateLimitMatch>

Determines which traffic the rate limit counts towards the threshold.

Link copied to clipboard
val period: Output<Double>

The time in seconds (an integer value) to count matching traffic. If the count exceeds the configured threshold within this period, Cloudflare will perform the configured action.

Link copied to clipboard
val pulumiChildResources: Set<KotlinResource>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val threshold: Output<Double>

The threshold that will trigger the configured mitigation action. Configure this value along with the period property to establish a threshold per period.

Link copied to clipboard
val urn: Output<String>
Link copied to clipboard
val zoneId: Output<String>

Identifier