Load Balancer Args
Provides a Cloudflare Load Balancer resource. This sits in front of a number of defined pools of origins and provides various options for geographically-aware load balancing. Note that the load balancing feature must be enabled in your Cloudflare account before you can use this resource.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as cloudflare from "@pulumi/cloudflare";
const exampleLoadBalancerPool = new cloudflare.LoadBalancerPool("example", {
name: "example-lb-pool",
origins: [{
name: "example-1",
address: "192.0.2.1",
enabled: false,
}],
});
// Define a load balancer which always points to a pool we define below.
// In normal usage, would have different pools set for different pops
// (cloudflare points-of-presence) and/or for different regions.
// Within each pop or region we can define multiple pools in failover order.
const example = new cloudflare.LoadBalancer("example", {
zoneId: "0da42c8d2132a9ddaf714f9e7c920711",
name: "example-load-balancer.example.com",
fallbackPoolId: exampleLoadBalancerPool.id,
defaultPoolIds: [exampleLoadBalancerPool.id],
description: "example load balancer using geo-balancing",
proxied: true,
steeringPolicy: "geo",
popPools: [{
pop: "LAX",
poolIds: [exampleLoadBalancerPool.id],
}],
countryPools: [{
country: "US",
poolIds: [exampleLoadBalancerPool.id],
}],
regionPools: [{
region: "WNAM",
poolIds: [exampleLoadBalancerPool.id],
}],
rules: [{
name: "example rule",
condition: "http.request.uri.path contains \"testing\"",
fixedResponse: {
messageBody: "hello",
statusCode: 200,
contentType: "html",
location: "www.example.com",
},
}],
});
import pulumi
import pulumi_cloudflare as cloudflare
example_load_balancer_pool = cloudflare.LoadBalancerPool("example",
name="example-lb-pool",
origins=[{
"name": "example-1",
"address": "192.0.2.1",
"enabled": False,
}])
# Define a load balancer which always points to a pool we define below.
# In normal usage, would have different pools set for different pops
# (cloudflare points-of-presence) and/or for different regions.
# Within each pop or region we can define multiple pools in failover order.
example = cloudflare.LoadBalancer("example",
zone_id="0da42c8d2132a9ddaf714f9e7c920711",
name="example-load-balancer.example.com",
fallback_pool_id=example_load_balancer_pool.id,
default_pool_ids=[example_load_balancer_pool.id],
description="example load balancer using geo-balancing",
proxied=True,
steering_policy="geo",
pop_pools=[{
"pop": "LAX",
"pool_ids": [example_load_balancer_pool.id],
}],
country_pools=[{
"country": "US",
"pool_ids": [example_load_balancer_pool.id],
}],
region_pools=[{
"region": "WNAM",
"pool_ids": [example_load_balancer_pool.id],
}],
rules=[{
"name": "example rule",
"condition": "http.request.uri.path contains \"testing\"",
"fixed_response": {
"message_body": "hello",
"status_code": 200,
"content_type": "html",
"location": "www.example.com",
},
}])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Cloudflare = Pulumi.Cloudflare;
return await Deployment.RunAsync(() =>
{
var exampleLoadBalancerPool = new Cloudflare.LoadBalancerPool("example", new()
{
Name = "example-lb-pool",
Origins = new[]
{
new Cloudflare.Inputs.LoadBalancerPoolOriginArgs
{
Name = "example-1",
Address = "192.0.2.1",
Enabled = false,
},
},
});
// Define a load balancer which always points to a pool we define below.
// In normal usage, would have different pools set for different pops
// (cloudflare points-of-presence) and/or for different regions.
// Within each pop or region we can define multiple pools in failover order.
var example = new Cloudflare.LoadBalancer("example", new()
{
ZoneId = "0da42c8d2132a9ddaf714f9e7c920711",
Name = "example-load-balancer.example.com",
FallbackPoolId = exampleLoadBalancerPool.Id,
DefaultPoolIds = new[]
{
exampleLoadBalancerPool.Id,
},
Description = "example load balancer using geo-balancing",
Proxied = true,
SteeringPolicy = "geo",
PopPools = new[]
{
new Cloudflare.Inputs.LoadBalancerPopPoolArgs
{
Pop = "LAX",
PoolIds = new[]
{
exampleLoadBalancerPool.Id,
},
},
},
CountryPools = new[]
{
new Cloudflare.Inputs.LoadBalancerCountryPoolArgs
{
Country = "US",
PoolIds = new[]
{
exampleLoadBalancerPool.Id,
},
},
},
RegionPools = new[]
{
new Cloudflare.Inputs.LoadBalancerRegionPoolArgs
{
Region = "WNAM",
PoolIds = new[]
{
exampleLoadBalancerPool.Id,
},
},
},
Rules = new[]
{
new Cloudflare.Inputs.LoadBalancerRuleArgs
{
Name = "example rule",
Condition = "http.request.uri.path contains \"testing\"",
FixedResponse = new Cloudflare.Inputs.LoadBalancerRuleFixedResponseArgs
{
MessageBody = "hello",
StatusCode = 200,
ContentType = "html",
Location = "www.example.com",
},
},
},
});
});
package main
import (
"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 {
exampleLoadBalancerPool, err := cloudflare.NewLoadBalancerPool(ctx, "example", &cloudflare.LoadBalancerPoolArgs{
Name: pulumi.String("example-lb-pool"),
Origins: cloudflare.LoadBalancerPoolOriginArray{
&cloudflare.LoadBalancerPoolOriginArgs{
Name: pulumi.String("example-1"),
Address: pulumi.String("192.0.2.1"),
Enabled: pulumi.Bool(false),
},
},
})
if err != nil {
return err
}
// Define a load balancer which always points to a pool we define below.
// In normal usage, would have different pools set for different pops
// (cloudflare points-of-presence) and/or for different regions.
// Within each pop or region we can define multiple pools in failover order.
_, err = cloudflare.NewLoadBalancer(ctx, "example", &cloudflare.LoadBalancerArgs{
ZoneId: pulumi.String("0da42c8d2132a9ddaf714f9e7c920711"),
Name: pulumi.String("example-load-balancer.example.com"),
FallbackPoolId: exampleLoadBalancerPool.ID(),
DefaultPoolIds: pulumi.StringArray{
exampleLoadBalancerPool.ID(),
},
Description: pulumi.String("example load balancer using geo-balancing"),
Proxied: pulumi.Bool(true),
SteeringPolicy: pulumi.String("geo"),
PopPools: cloudflare.LoadBalancerPopPoolArray{
&cloudflare.LoadBalancerPopPoolArgs{
Pop: pulumi.String("LAX"),
PoolIds: pulumi.StringArray{
exampleLoadBalancerPool.ID(),
},
},
},
CountryPools: cloudflare.LoadBalancerCountryPoolArray{
&cloudflare.LoadBalancerCountryPoolArgs{
Country: pulumi.String("US"),
PoolIds: pulumi.StringArray{
exampleLoadBalancerPool.ID(),
},
},
},
RegionPools: cloudflare.LoadBalancerRegionPoolArray{
&cloudflare.LoadBalancerRegionPoolArgs{
Region: pulumi.String("WNAM"),
PoolIds: pulumi.StringArray{
exampleLoadBalancerPool.ID(),
},
},
},
Rules: cloudflare.LoadBalancerRuleArray{
&cloudflare.LoadBalancerRuleArgs{
Name: pulumi.String("example rule"),
Condition: pulumi.String("http.request.uri.path contains \"testing\""),
FixedResponse: &cloudflare.LoadBalancerRuleFixedResponseArgs{
MessageBody: pulumi.String("hello"),
StatusCode: pulumi.Int(200),
ContentType: pulumi.String("html"),
Location: pulumi.String("www.example.com"),
},
},
},
})
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.LoadBalancerPool;
import com.pulumi.cloudflare.LoadBalancerPoolArgs;
import com.pulumi.cloudflare.inputs.LoadBalancerPoolOriginArgs;
import com.pulumi.cloudflare.LoadBalancer;
import com.pulumi.cloudflare.LoadBalancerArgs;
import com.pulumi.cloudflare.inputs.LoadBalancerPopPoolArgs;
import com.pulumi.cloudflare.inputs.LoadBalancerCountryPoolArgs;
import com.pulumi.cloudflare.inputs.LoadBalancerRegionPoolArgs;
import com.pulumi.cloudflare.inputs.LoadBalancerRuleArgs;
import com.pulumi.cloudflare.inputs.LoadBalancerRuleFixedResponseArgs;
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 exampleLoadBalancerPool = new LoadBalancerPool("exampleLoadBalancerPool", LoadBalancerPoolArgs.builder()
.name("example-lb-pool")
.origins(LoadBalancerPoolOriginArgs.builder()
.name("example-1")
.address("192.0.2.1")
.enabled(false)
.build())
.build());
// Define a load balancer which always points to a pool we define below.
// In normal usage, would have different pools set for different pops
// (cloudflare points-of-presence) and/or for different regions.
// Within each pop or region we can define multiple pools in failover order.
var example = new LoadBalancer("example", LoadBalancerArgs.builder()
.zoneId("0da42c8d2132a9ddaf714f9e7c920711")
.name("example-load-balancer.example.com")
.fallbackPoolId(exampleLoadBalancerPool.id())
.defaultPoolIds(exampleLoadBalancerPool.id())
.description("example load balancer using geo-balancing")
.proxied(true)
.steeringPolicy("geo")
.popPools(LoadBalancerPopPoolArgs.builder()
.pop("LAX")
.poolIds(exampleLoadBalancerPool.id())
.build())
.countryPools(LoadBalancerCountryPoolArgs.builder()
.country("US")
.poolIds(exampleLoadBalancerPool.id())
.build())
.regionPools(LoadBalancerRegionPoolArgs.builder()
.region("WNAM")
.poolIds(exampleLoadBalancerPool.id())
.build())
.rules(LoadBalancerRuleArgs.builder()
.name("example rule")
.condition("http.request.uri.path contains \"testing\"")
.fixedResponse(LoadBalancerRuleFixedResponseArgs.builder()
.messageBody("hello")
.statusCode(200)
.contentType("html")
.location("www.example.com")
.build())
.build())
.build());
}
}
resources:
# Define a load balancer which always points to a pool we define below.
# In normal usage, would have different pools set for different pops
# (cloudflare points-of-presence) and/or for different regions.
# Within each pop or region we can define multiple pools in failover order.
example:
type: cloudflare:LoadBalancer
properties:
zoneId: 0da42c8d2132a9ddaf714f9e7c920711
name: example-load-balancer.example.com
fallbackPoolId: ${exampleLoadBalancerPool.id}
defaultPoolIds:
- ${exampleLoadBalancerPool.id}
description: example load balancer using geo-balancing
proxied: true
steeringPolicy: geo
popPools:
- pop: LAX
poolIds:
- ${exampleLoadBalancerPool.id}
countryPools:
- country: US
poolIds:
- ${exampleLoadBalancerPool.id}
regionPools:
- region: WNAM
poolIds:
- ${exampleLoadBalancerPool.id}
rules:
- name: example rule
condition: http.request.uri.path contains "testing"
fixedResponse:
messageBody: hello
statusCode: 200
contentType: html
location: www.example.com
exampleLoadBalancerPool:
type: cloudflare:LoadBalancerPool
name: example
properties:
name: example-lb-pool
origins:
- name: example-1
address: 192.0.2.1
enabled: false
Import
$ pulumi import cloudflare:index/loadBalancer:LoadBalancer example <zone_id>/<load_balancer_id>
Constructors
Properties
Controls features that modify the routing of requests to pools and origins in response to dynamic conditions, such as during the interval between active health monitoring requests.
A set containing mappings of country codes to a list of pool IDs (ordered by their failover priority) for the given country.
A list of pool IDs ordered by their failover priority. Used whenever pop_pools
/country_pools
/region_pools
are not defined.
Free text description.
The pool ID to use when all other pools are detected as unhealthy.
Controls location-based steering for non-proxied requests.
A set containing mappings of Cloudflare Point-of-Presence (PoP) identifiers to a list of pool IDs (ordered by their failover priority) for the PoP (datacenter). This feature is only available to enterprise customers.
Configures pool weights. When steering_policy="random"
, a random pool is selected with probability proportional to pool weights. When steering_policy="least_outstanding_requests"
, pool weights are used to scale each pool's outstanding requests. When steering_policy="least_connections"
, pool weights are used to scale each pool's open connections.
A set containing mappings of region codes to a list of pool IDs (ordered by their failover priority) for the given region.
A list of rules for this load balancer to execute.
Specifies the type of session affinity the load balancer should use unless specified as none
or ""
(default). With value cookie
, on the first request to a proxied load balancer, a cookie is generated, encoding information of which origin the request will be forwarded to. Subsequent requests, by the same client to the same load balancer, will be sent to the origin server the cookie encodes, for the duration of the cookie and as long as the origin server remains healthy. If the cookie has expired or the origin server is unhealthy then a new origin server is calculated and used. Value ip_cookie
behaves the same as cookie
except the initial origin selection is stable and based on the client's IP address. Available values: ""
, none
, cookie
, ip_cookie
, header
. Defaults to none
.
Configure attributes for session affinity.
Time, in seconds, until this load balancer's session affinity cookie expires after being created. This parameter is ignored unless a supported session affinity policy is set. The current default of 82800
(23 hours) will be used unless session_affinity_ttl
is explicitly set. Once the expiry time has been reached, subsequent requests may get sent to a different origin server. Valid values are between 1800
and 604800
.
The method the load balancer uses to determine the route to your origin. Value off
uses default_pool_ids
. Value geo
uses pop_pools
/country_pools
/region_pools
. For non-proxied requests, the country
for country_pools
is determined by location_strategy
. Value random
selects a pool randomly. Value dynamic_latency
uses round trip time to select the closest pool in default_pool_ids
(requires pool health checks). Value proximity
uses the pools' latitude and longitude to select the closest pool using the Cloudflare PoP location for proxied requests or the location determined by location_strategy
for non-proxied requests. Value least_outstanding_requests
selects a pool by taking into consideration random_steering
weights, as well as each pool's number of outstanding requests. Pools with more pending requests are weighted proportionately less relative to others. Value least_connections
selects a pool by taking into consideration random_steering
weights, as well as each pool's number of open connections. Pools with more open connections are weighted proportionately less relative to others. Supported for HTTP/1 and HTTP/2 connections. Value ""
maps to geo
if you use pop_pools
/country_pools
/region_pools
otherwise off
. Available values: off
, geo
, dynamic_latency
, random
, proximity
, least_outstanding_requests
, least_connections
, ""
Defaults to ""
.