![JAR search and dependency download from the Maven repository](/logo.png)
com.pulumi.cloudflare.kotlin.RateLimit.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pulumi-cloudflare-kotlin Show documentation
Show all versions of pulumi-cloudflare-kotlin Show documentation
Build cloud applications and infrastructure by combining the safety and reliability of infrastructure as code with the power of the Kotlin programming language.
@file:Suppress("NAME_SHADOWING", "DEPRECATION")
package com.pulumi.cloudflare.kotlin
import com.pulumi.cloudflare.kotlin.outputs.RateLimitAction
import com.pulumi.cloudflare.kotlin.outputs.RateLimitCorrelate
import com.pulumi.cloudflare.kotlin.outputs.RateLimitMatch
import com.pulumi.core.Output
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import com.pulumi.cloudflare.kotlin.outputs.RateLimitAction.Companion.toKotlin as rateLimitActionToKotlin
import com.pulumi.cloudflare.kotlin.outputs.RateLimitCorrelate.Companion.toKotlin as rateLimitCorrelateToKotlin
import com.pulumi.cloudflare.kotlin.outputs.RateLimitMatch.Companion.toKotlin as rateLimitMatchToKotlin
/**
* Builder for [RateLimit].
*/
@PulumiTagMarker
public class RateLimitResourceBuilder internal constructor() {
public var name: String? = null
public var args: RateLimitArgs = RateLimitArgs()
public var opts: CustomResourceOptions = CustomResourceOptions()
/**
* @param name The _unique_ name of the resulting resource.
*/
public fun name(`value`: String) {
this.name = value
}
/**
* @param block The arguments to use to populate this resource's properties.
*/
public suspend fun args(block: suspend RateLimitArgsBuilder.() -> Unit) {
val builder = RateLimitArgsBuilder()
block(builder)
this.args = builder.build()
}
/**
* @param block A bag of options that control this resource's behavior.
*/
public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
}
internal fun build(): RateLimit {
val builtJavaResource = com.pulumi.cloudflare.RateLimit(
this.name,
this.args.toJava(),
this.opts.toJava(),
)
return RateLimit(builtJavaResource)
}
}
/**
* Provides a Cloudflare rate limit resource for a given zone. This can
* be used to limit the traffic you receive zone-wide, or matching more
* specific types of requests/responses.
* > `cloudflare.RateLimit` is in a deprecation phase until January 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
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as cloudflare from "@pulumi/cloudflare";
* const example = new cloudflare.RateLimit("example", {
* zoneId: "0da42c8d2132a9ddaf714f9e7c920711",
* threshold: 2000,
* period: 2,
* match: {
* request: {
* urlPattern: `${cloudflareZone}/*`,
* schemes: [
* "HTTP",
* "HTTPS",
* ],
* methods: [
* "GET",
* "POST",
* "PUT",
* "DELETE",
* "PATCH",
* "HEAD",
* ],
* },
* response: {
* statuses: [
* 200,
* 201,
* 202,
* 301,
* 429,
* ],
* originTraffic: false,
* headers: [
* {
* name: "Host",
* op: "eq",
* value: "localhost",
* },
* {
* name: "X-Example",
* op: "ne",
* value: "my-example",
* },
* ],
* },
* },
* action: {
* mode: "simulate",
* timeout: 43200,
* response: {
* contentType: "text/plain",
* body: "custom response body",
* },
* },
* correlate: {
* by: "nat",
* },
* disabled: false,
* description: "example rate limit for a zone",
* bypassUrlPatterns: [
* "example.com/bypass1",
* "example.com/bypass2",
* ],
* });
* ```
* ```python
* import pulumi
* import pulumi_cloudflare as cloudflare
* example = cloudflare.RateLimit("example",
* zone_id="0da42c8d2132a9ddaf714f9e7c920711",
* threshold=2000,
* period=2,
* match={
* "request": {
* "url_pattern": f"{cloudflare_zone}/*",
* "schemes": [
* "HTTP",
* "HTTPS",
* ],
* "methods": [
* "GET",
* "POST",
* "PUT",
* "DELETE",
* "PATCH",
* "HEAD",
* ],
* },
* "response": {
* "statuses": [
* 200,
* 201,
* 202,
* 301,
* 429,
* ],
* "origin_traffic": False,
* "headers": [
* {
* "name": "Host",
* "op": "eq",
* "value": "localhost",
* },
* {
* "name": "X-Example",
* "op": "ne",
* "value": "my-example",
* },
* ],
* },
* },
* action={
* "mode": "simulate",
* "timeout": 43200,
* "response": {
* "content_type": "text/plain",
* "body": "custom response body",
* },
* },
* correlate={
* "by": "nat",
* },
* disabled=False,
* description="example rate limit for a zone",
* bypass_url_patterns=[
* "example.com/bypass1",
* "example.com/bypass2",
* ])
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Cloudflare = Pulumi.Cloudflare;
* return await Deployment.RunAsync(() =>
* {
* var example = new Cloudflare.RateLimit("example", new()
* {
* ZoneId = "0da42c8d2132a9ddaf714f9e7c920711",
* Threshold = 2000,
* Period = 2,
* Match = new Cloudflare.Inputs.RateLimitMatchArgs
* {
* Request = new Cloudflare.Inputs.RateLimitMatchRequestArgs
* {
* UrlPattern = $"{cloudflareZone}/*",
* Schemes = new[]
* {
* "HTTP",
* "HTTPS",
* },
* Methods = new[]
* {
* "GET",
* "POST",
* "PUT",
* "DELETE",
* "PATCH",
* "HEAD",
* },
* },
* Response = new Cloudflare.Inputs.RateLimitMatchResponseArgs
* {
* Statuses = new[]
* {
* 200,
* 201,
* 202,
* 301,
* 429,
* },
* OriginTraffic = false,
* Headers = new[]
* {
* {
* { "name", "Host" },
* { "op", "eq" },
* { "value", "localhost" },
* },
* {
* { "name", "X-Example" },
* { "op", "ne" },
* { "value", "my-example" },
* },
* },
* },
* },
* Action = new Cloudflare.Inputs.RateLimitActionArgs
* {
* Mode = "simulate",
* Timeout = 43200,
* Response = new Cloudflare.Inputs.RateLimitActionResponseArgs
* {
* ContentType = "text/plain",
* Body = "custom response body",
* },
* },
* Correlate = new Cloudflare.Inputs.RateLimitCorrelateArgs
* {
* By = "nat",
* },
* Disabled = false,
* Description = "example rate limit for a zone",
* BypassUrlPatterns = new[]
* {
* "example.com/bypass1",
* "example.com/bypass2",
* },
* });
* });
* ```
* ```go
* package main
* import (
* "fmt"
* "github.com/pulumi/pulumi-cloudflare/sdk/v5/go/cloudflare"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* _, err := cloudflare.NewRateLimit(ctx, "example", &cloudflare.RateLimitArgs{
* ZoneId: pulumi.String("0da42c8d2132a9ddaf714f9e7c920711"),
* Threshold: pulumi.Int(2000),
* Period: pulumi.Int(2),
* Match: &cloudflare.RateLimitMatchArgs{
* Request: &cloudflare.RateLimitMatchRequestArgs{
* UrlPattern: pulumi.Sprintf("%v/*", cloudflareZone),
* Schemes: pulumi.StringArray{
* pulumi.String("HTTP"),
* pulumi.String("HTTPS"),
* },
* Methods: pulumi.StringArray{
* pulumi.String("GET"),
* pulumi.String("POST"),
* pulumi.String("PUT"),
* pulumi.String("DELETE"),
* pulumi.String("PATCH"),
* pulumi.String("HEAD"),
* },
* },
* Response: &cloudflare.RateLimitMatchResponseArgs{
* Statuses: pulumi.IntArray{
* pulumi.Int(200),
* pulumi.Int(201),
* pulumi.Int(202),
* pulumi.Int(301),
* pulumi.Int(429),
* },
* OriginTraffic: pulumi.Bool(false),
* Headers: pulumi.StringMapArray{
* pulumi.StringMap{
* "name": pulumi.String("Host"),
* "op": pulumi.String("eq"),
* "value": pulumi.String("localhost"),
* },
* pulumi.StringMap{
* "name": pulumi.String("X-Example"),
* "op": pulumi.String("ne"),
* "value": pulumi.String("my-example"),
* },
* },
* },
* },
* Action: &cloudflare.RateLimitActionArgs{
* Mode: pulumi.String("simulate"),
* Timeout: pulumi.Int(43200),
* Response: &cloudflare.RateLimitActionResponseArgs{
* ContentType: pulumi.String("text/plain"),
* Body: pulumi.String("custom response body"),
* },
* },
* Correlate: &cloudflare.RateLimitCorrelateArgs{
* By: pulumi.String("nat"),
* },
* Disabled: pulumi.Bool(false),
* Description: pulumi.String("example rate limit for a zone"),
* BypassUrlPatterns: pulumi.StringArray{
* pulumi.String("example.com/bypass1"),
* pulumi.String("example.com/bypass2"),
* },
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* 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.RateLimitMatchArgs;
* import com.pulumi.cloudflare.inputs.RateLimitMatchRequestArgs;
* import com.pulumi.cloudflare.inputs.RateLimitMatchResponseArgs;
* import com.pulumi.cloudflare.inputs.RateLimitActionArgs;
* import com.pulumi.cloudflare.inputs.RateLimitActionResponseArgs;
* import com.pulumi.cloudflare.inputs.RateLimitCorrelateArgs;
* 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 example = new RateLimit("example", RateLimitArgs.builder()
* .zoneId("0da42c8d2132a9ddaf714f9e7c920711")
* .threshold(2000)
* .period(2)
* .match(RateLimitMatchArgs.builder()
* .request(RateLimitMatchRequestArgs.builder()
* .urlPattern(String.format("%s/*", cloudflareZone))
* .schemes(
* "HTTP",
* "HTTPS")
* .methods(
* "GET",
* "POST",
* "PUT",
* "DELETE",
* "PATCH",
* "HEAD")
* .build())
* .response(RateLimitMatchResponseArgs.builder()
* .statuses(
* 200,
* 201,
* 202,
* 301,
* 429)
* .originTraffic(false)
* .headers(
* Map.ofEntries(
* Map.entry("name", "Host"),
* Map.entry("op", "eq"),
* Map.entry("value", "localhost")
* ),
* Map.ofEntries(
* Map.entry("name", "X-Example"),
* Map.entry("op", "ne"),
* Map.entry("value", "my-example")
* ))
* .build())
* .build())
* .action(RateLimitActionArgs.builder()
* .mode("simulate")
* .timeout(43200)
* .response(RateLimitActionResponseArgs.builder()
* .contentType("text/plain")
* .body("custom response body")
* .build())
* .build())
* .correlate(RateLimitCorrelateArgs.builder()
* .by("nat")
* .build())
* .disabled(false)
* .description("example rate limit for a zone")
* .bypassUrlPatterns(
* "example.com/bypass1",
* "example.com/bypass2")
* .build());
* }
* }
* ```
* ```yaml
* resources:
* example:
* type: cloudflare:RateLimit
* properties:
* zoneId: 0da42c8d2132a9ddaf714f9e7c920711
* threshold: 2000
* period: 2
* match:
* request:
* urlPattern: ${cloudflareZone}/*
* schemes:
* - HTTP
* - HTTPS
* methods:
* - GET
* - POST
* - PUT
* - DELETE
* - PATCH
* - HEAD
* response:
* statuses:
* - 200
* - 201
* - 202
* - 301
* - 429
* originTraffic: false
* headers:
* - name: Host
* op: eq
* value: localhost
* - name: X-Example
* op: ne
* value: my-example
* action:
* mode: simulate
* timeout: 43200
* response:
* contentType: text/plain
* body: custom response body
* correlate:
* by: nat
* disabled: false
* description: example rate limit for a zone
* bypassUrlPatterns:
* - example.com/bypass1
* - example.com/bypass2
* ```
*
* ## Import
* ```sh
* $ pulumi import cloudflare:index/rateLimit:RateLimit example /
* ```
* */*/*/*/*/*/
*/
public class RateLimit internal constructor(
override val javaResource: com.pulumi.cloudflare.RateLimit,
) : KotlinCustomResource(javaResource, RateLimitMapper) {
/**
* The action to be performed when the threshold of matched traffic within the period defined is exceeded.
*/
public val action: Output
get() = javaResource.action().applyValue({ args0 ->
args0.let({ args0 ->
rateLimitActionToKotlin(args0)
})
})
public val bypassUrlPatterns: Output>?
get() = javaResource.bypassUrlPatterns().applyValue({ args0 ->
args0.map({ args0 ->
args0.map({ args0 -> args0 })
}).orElse(null)
})
/**
* Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
*/
public val correlate: Output?
get() = javaResource.correlate().applyValue({ args0 ->
args0.map({ args0 ->
args0.let({ args0 ->
rateLimitCorrelateToKotlin(args0)
})
}).orElse(null)
})
/**
* A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
*/
public val description: Output?
get() = javaResource.description().applyValue({ args0 ->
args0.map({ args0 ->
args0
}).orElse(null)
})
/**
* Whether this ratelimit is currently disabled. Defaults to `false`.
*/
public val disabled: Output?
get() = javaResource.disabled().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
/**
* Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone.
*/
public val match: Output
get() = javaResource.match().applyValue({ args0 ->
args0.let({ args0 ->
rateLimitMatchToKotlin(args0)
})
})
/**
* The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed.
*/
public val period: Output
get() = javaResource.period().applyValue({ args0 -> args0 })
/**
* The threshold that triggers the rate limit mitigations, combine with period.
*/
public val threshold: Output
get() = javaResource.threshold().applyValue({ args0 -> args0 })
/**
* The zone identifier to target for the resource. **Modifying this attribute will force creation of a new resource.**
*/
public val zoneId: Output
get() = javaResource.zoneId().applyValue({ args0 -> args0 })
}
public object RateLimitMapper : ResourceMapper {
override fun supportsMappingOfType(javaResource: Resource): Boolean =
com.pulumi.cloudflare.RateLimit::class == javaResource::class
override fun map(javaResource: Resource): RateLimit = RateLimit(
javaResource as
com.pulumi.cloudflare.RateLimit,
)
}
/**
* @see [RateLimit].
* @param name The _unique_ name of the resulting resource.
* @param block Builder for [RateLimit].
*/
public suspend fun rateLimit(name: String, block: suspend RateLimitResourceBuilder.() -> Unit): RateLimit {
val builder = RateLimitResourceBuilder()
builder.name(name)
block(builder)
return builder.build()
}
/**
* @see [RateLimit].
* @param name The _unique_ name of the resulting resource.
*/
public fun rateLimit(name: String): RateLimit {
val builder = RateLimitResourceBuilder()
builder.name(name)
return builder.build()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy