cloudflare_load_balancer (Resource)

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

# 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.
resource "cloudflare_load_balancer" "example" {
  zone_id          = "0da42c8d2132a9ddaf714f9e7c920711"
  name             = "example-load-balancer.example.com"
  fallback_pool_id = cloudflare_load_balancer_pool.example.id
  default_pool_ids = [cloudflare_load_balancer_pool.example.id]
  description      = "example load balancer using geo-balancing"
  proxied          = true
  steering_policy  = "geo"

  pop_pools {
    pop      = "LAX"
    pool_ids = [cloudflare_load_balancer_pool.example.id]
  }

  country_pools {
    country  = "US"
    pool_ids = [cloudflare_load_balancer_pool.example.id]
  }

  region_pools {
    region   = "WNAM"
    pool_ids = [cloudflare_load_balancer_pool.example.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"
    }
  }
}

resource "cloudflare_load_balancer_pool" "example" {
  name = "example-lb-pool"
  origins {
    name    = "example-1"
    address = "192.0.2.1"
    enabled = false
  }
}

Schema

Required

Optional

Read-Only

Nested Schema for adaptive_routing

Optional:

Nested Schema for country_pools

Required:

Nested Schema for location_strategy

Optional:

Nested Schema for pop_pools

Required:

Nested Schema for random_steering

Optional:

Nested Schema for region_pools

Required:

Nested Schema for rules

Required:

Optional:

Nested Schema for rules.fixed_response

Optional:

Nested Schema for rules.overrides

Optional:

Nested Schema for rules.overrides.adaptive_routing

Optional:

Nested Schema for rules.overrides.country_pools

Required:

Nested Schema for rules.overrides.location_strategy

Optional:

Nested Schema for rules.overrides.pop_pools

Required:

Nested Schema for rules.overrides.random_steering

Optional:

Nested Schema for rules.overrides.region_pools

Required:

Nested Schema for rules.overrides.session_affinity_attributes

Optional:

Nested Schema for session_affinity_attributes

Optional:

Import

Import is supported using the following syntax:

$ terraform import cloudflare_load_balancer.example <zone_id>/<load_balancer_id>