Skip to content

Commit

Permalink
Merge f58b511 into be080c8
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilfar authored Dec 21, 2018
2 parents be080c8 + f58b511 commit d4a55df
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ func resourceComputeBackendService() *schema.Resource {
Computed: true,
},

"affinity_cookie_ttl_sec": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},

"timeout_sec": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -313,6 +318,7 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{})
d.Set("port_name", service.PortName)
d.Set("protocol", service.Protocol)
d.Set("session_affinity", service.SessionAffinity)
d.Set("affinity_cookie_ttl_sec", service.AffinityCookieTtlSec)
d.Set("timeout_sec", service.TimeoutSec)
d.Set("fingerprint", service.Fingerprint)
d.Set("self_link", ConvertSelfLinkToV1(service.SelfLink))
Expand Down Expand Up @@ -572,6 +578,10 @@ func expandBackendService(d *schema.ResourceData) (*computeBeta.BackendService,
service.SessionAffinity = v.(string)
}

if v, ok := d.GetOk("affinity_cookie_ttl_sec"); ok {
service.AffinityCookieTtlSec = int64(v.(int))
}

if v, ok := d.GetOk("timeout_sec"); ok {
service.TimeoutSec = int64(v.(int))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,38 @@ func TestAccComputeBackendService_withSessionAffinity(t *testing.T) {
}
}

func TestAccComputeBackendService_withAffinityCookieTtlSec(t *testing.T) {
t.Parallel()

serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
var svc compute.BackendService

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeBackendService_withAffinityCookieTtlSec(
serviceName, checkName, "description", "GENERATED_COOKIE", 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBackendServiceExists(
"google_compute_backend_service.foobar", &svc),
),
},
},
})

if svc.SessionAffinity != "GENERATED_COOKIE" {
t.Errorf("Expected SessionAffinity == \"GENERATED_COOKIE\", got %s", svc.SessionAffinity)
}

if svc.AffinityCookieTtlSec != 300 {
t.Errorf("Expected AffinityCookieTtlSec == 300, got %v", svc.AffinityCookieTtlSec)
}
}

func TestAccComputeBackendService_withMaxConnections(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -823,6 +855,24 @@ resource "google_compute_http_health_check" "zero" {
`, serviceName, description, affinityName, checkName)
}

func testAccComputeBackendService_withAffinityCookieTtlSec(serviceName, checkName, description, affinityName string, affinityCookieTtlSec int64) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
name = "%s"
description = "%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
session_affinity = "%s"
affinity_cookie_ttl_sec = %v
}
resource "google_compute_http_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
`, serviceName, description, affinityName, affinityCookieTtlSec, checkName)
}

func testAccComputeBackendService_withConnectionDraining(serviceName, checkName string, drainingTimeout int64) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ but still work to finish started ones). Defaults to `300`.
affinity), `CLIENT_IP` (hash of the source/dest addresses / ports), and
`GENERATED_COOKIE` (distribute load using a generated session cookie).

* `affinity_cookie_ttl_sec` - (Optional) Lifetime of cookies in seconds if session_affinity is
`GENERATED_COOKIE`. If set to 0, the cookie is non-persistent and lasts only until the end of
the browser session (or equivalent). The maximum allowed value for TTL is one day.

* `timeout_sec` - (Optional) The number of secs to wait for a backend to respond
to a request before considering the request failed. Defaults to `30`.

Expand Down

0 comments on commit d4a55df

Please sign in to comment.