Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudflare_load_balancer: add ip_cookie as a valid session_affinity option #573

Merged
merged 2 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloudflare/resource_cloudflare_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func resourceCloudflareLoadBalancer() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "none",
ValidateFunc: validation.StringInSlice([]string{"none", "cookie"}, false),
ValidateFunc: validation.StringInSlice([]string{"", "none", "cookie", "ip_cookie"}, false),
},

"proxied": {
Expand Down
32 changes: 32 additions & 0 deletions cloudflare/resource_cloudflare_load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ func TestAccCloudflareLoadBalancer_SessionAffinity(t *testing.T) {
},
},
})

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudflareLoadBalancerDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudflareLoadBalancerConfigSessionAffinityIPCookie(zoneID, zone, rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareLoadBalancerExists(name, &loadBalancer),
testAccCheckCloudflareLoadBalancerIDIsValid(name, zoneID),
// explicitly verify that our session_affinity has been set
resource.TestCheckResourceAttr(name, "session_affinity", "ip_cookie"),
// dont check that other specified values are set, this will be evident by lack
// of plan diff some values will get empty values
resource.TestCheckResourceAttr(name, "pop_pools.#", "0"),
resource.TestCheckResourceAttr(name, "region_pools.#", "0"),
),
},
},
})
}

func TestAccCloudflareLoadBalancer_GeoBalanced(t *testing.T) {
Expand Down Expand Up @@ -344,6 +365,17 @@ resource "cloudflare_load_balancer" "%[3]s" {
}`, zoneID, zone, id)
}

func testAccCheckCloudflareLoadBalancerConfigSessionAffinityIPCookie(zoneID, zone, id string) string {
return testAccCheckCloudflareLoadBalancerPoolConfigBasic(id) + fmt.Sprintf(`
resource "cloudflare_load_balancer" "%[3]s" {
zone_id = "%[1]s"
name = "tf-testacc-lb-session-affinity-%[3]s.%[2]s"
fallback_pool_id = "${cloudflare_load_balancer_pool.%[3]s.id}"
default_pool_ids = ["${cloudflare_load_balancer_pool.%[3]s.id}"]
session_affinity = "ip_cookie"
}`, zoneID, zone, id)
}

func testAccCheckCloudflareLoadBalancerConfigGeoBalanced(zoneID, zone, id string) string {
return testAccCheckCloudflareLoadBalancerPoolConfigBasic(id) + fmt.Sprintf(`
resource "cloudflare_load_balancer" "%[3]s" {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/load_balancer.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ The following arguments are supported:
* `default_pool_ids` - (Required) A list of pool IDs ordered by their failover priority. Used whenever region/pop pools are not defined.
* `description` - (Optional) Free text description.
* `ttl` - (Optional) Time to live (TTL) of this load balancer's DNS `name`. Conflicts with `proxied` - this cannot be set for proxied load balancers. Default is `30`.
* `steering_policy` - (Optional) Determine which method the load balancer uses to determine the fastest route to your origin. Valid values are: `"off"`, `"geo"`, `"dynamic_latency"`, `"random"` or `""`. Default is `""`.
* `steering_policy` - (Optional) Determine which method the load balancer uses to determine the fastest route to your origin. Valid values are: `"off"`, `"geo"`, `"dynamic_latency"`, `"random"` or `""`. Default is `""`.
* `proxied` - (Optional) Whether the hostname gets Cloudflare's origin protection. Defaults to `false`.
* `enabled` - (Optional) Enable or disable the load balancer. Defaults to `true` (enabled).
* `region_pools` - (Optional) A set containing mappings of region/country codes to a list of pool IDs (ordered by their failover priority) for the given region. Fields documented below.
* `pop_pools` - (Optional) 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. Fields documented below.
* `session_affinity` - (Optional) Associates all requests coming from an end-user with a single origin. Cloudflare will set a cookie on the initial response to the client, such that consequent requests with the cookie in the request will go to the same origin, so long as it is available.
* `session_affinity` - (Optional) Associates all requests coming from an end-user with a single origin. Cloudflare will set a cookie on the initial response to the client, such that consequent requests with the cookie in the request will go to the same origin, so long as it is available. Valid values are: `""`, `"none"`, `"cookie"`, and `"ip_cookie"`. Default is `""`.

**region_pools** requires the following:

Expand Down