@ -187,6 +187,40 @@ func TestAccComputeBackendService_withCDNEnabled(t *testing.T) {
}
}
func TestAccComputeBackendService_withSessionAffinity ( t * testing . T ) {
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_withSessionAffinity (
serviceName , checkName , "CLIENT_IP" ) ,
Check : resource . ComposeTestCheckFunc (
testAccCheckComputeBackendServiceExists (
"google_compute_backend_service.foobar" , & svc ) ,
) ,
} ,
resource . TestStep {
Config : testAccComputeBackendService_withSessionAffinity (
serviceName , checkName , "GENERATED_COOKIE" ) ,
Check : resource . ComposeTestCheckFunc (
testAccCheckComputeBackendServiceExists (
"google_compute_backend_service.foobar" , & svc ) ,
) ,
} ,
} ,
} )
if svc . SessionAffinity != "GENERATED_COOKIE" {
t . Errorf ( "Expected SessionAffinity == \"GENERATED_COOKIE\", got %t" , svc . SessionAffinity )
}
}
func testAccComputeBackendService_basic ( serviceName , checkName string ) string {
return fmt . Sprintf ( `
resource "google_compute_backend_service" "foobar" {
@ -291,3 +325,20 @@ resource "google_compute_http_health_check" "default" {
}
` , serviceName , timeout , igName , itName , checkName )
}
func testAccComputeBackendService_withSessionAffinity ( serviceName , checkName , affinityName string ) string {
return fmt . Sprintf ( `
resource "google_compute_backend_service" "foobar" {
name = "%s"
health_checks = [ "${google_compute_http_health_check.zero.self_link}" ]
session_affinity = "%s"
}
resource "google_compute_http_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
` , serviceName , affinityName , checkName )
}