Add support for session_affinity to google_compute_region_backend_service
This commit is contained in:
parent
b61729bbaf
commit
73bd728fe5
|
@ -82,6 +82,12 @@ func resourceComputeRegionBackendService() *schema.Resource {
|
|||
Computed: true,
|
||||
},
|
||||
|
||||
"session_affinity": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -129,6 +135,10 @@ func resourceComputeRegionBackendServiceCreate(d *schema.ResourceData, meta inte
|
|||
service.Protocol = v.(string)
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("session_affinity"); ok {
|
||||
service.SessionAffinity = v.(string)
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("timeout_sec"); ok {
|
||||
service.TimeoutSec = int64(v.(int))
|
||||
}
|
||||
|
@ -192,6 +202,7 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf
|
|||
|
||||
d.Set("description", service.Description)
|
||||
d.Set("protocol", service.Protocol)
|
||||
d.Set("session_affinity", service.SessionAffinity)
|
||||
d.Set("timeout_sec", service.TimeoutSec)
|
||||
d.Set("fingerprint", service.Fingerprint)
|
||||
d.Set("self_link", service.SelfLink)
|
||||
|
@ -238,6 +249,9 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte
|
|||
if v, ok := d.GetOk("protocol"); ok {
|
||||
service.Protocol = v.(string)
|
||||
}
|
||||
if v, ok := d.GetOk("session_affinity"); ok {
|
||||
service.SessionAffinity = v.(string)
|
||||
}
|
||||
if v, ok := d.GetOk("timeout_sec"); ok {
|
||||
service.TimeoutSec = int64(v.(int))
|
||||
}
|
||||
|
|
|
@ -114,6 +114,32 @@ func TestAccComputeRegionBackendService_withBackendAndUpdate(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAccComputeRegionBackendService_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: testAccCheckComputeRegionBackendServiceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeRegionBackendService_withSessionAffinity(
|
||||
serviceName, checkName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeRegionBackendServiceExists(
|
||||
"google_compute_region_backend_service.foobar", &svc),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if svc.SessionAffinity != "CLIENT_IP" {
|
||||
t.Errorf("Expected Protocol to be CLIENT_IP, got %q", svc.SessionAffinity)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckComputeRegionBackendServiceDestroy(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
|
||||
|
@ -253,10 +279,32 @@ resource "google_compute_health_check" "default" {
|
|||
name = "%s"
|
||||
check_interval_sec = 1
|
||||
timeout_sec = 1
|
||||
|
||||
|
||||
tcp_health_check {
|
||||
|
||||
}
|
||||
}
|
||||
`, serviceName, timeout, igName, itName, checkName)
|
||||
}
|
||||
|
||||
func testAccComputeRegionBackendService_withSessionAffinity(serviceName, checkName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_region_backend_service" "foobar" {
|
||||
name = "%s"
|
||||
health_checks = ["${google_compute_health_check.zero.self_link}"]
|
||||
region = "us-central1"
|
||||
session_affinity = "CLIENT_IP"
|
||||
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "zero" {
|
||||
name = "%s"
|
||||
check_interval_sec = 1
|
||||
timeout_sec = 1
|
||||
|
||||
tcp_health_check {
|
||||
port = "80"
|
||||
}
|
||||
}
|
||||
`, serviceName, checkName)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ resource "google_compute_region_backend_service" "foobar" {
|
|||
description = "Hello World 1234"
|
||||
protocol = "TCP"
|
||||
timeout_sec = 10
|
||||
session_affinity = "CLIENT_IP"
|
||||
|
||||
backend {
|
||||
group = "${google_compute_instance_group_manager.foo.instance_group}"
|
||||
|
@ -84,6 +85,10 @@ The following arguments are supported:
|
|||
* `protocol` - (Optional) The protocol for incoming requests. Defaults to
|
||||
`HTTP`.
|
||||
|
||||
* `session_affinity` - (Optional) How to distribute load. Options are `NONE` (no
|
||||
affinity), `CLIENT_IP`, `CLIENT_IP_PROTO`, or `CLIENT_IP_PORT_PROTO`.
|
||||
Defaults to `NONE`.
|
||||
|
||||
* `region` - (Optional) The Region in which the created address should reside.
|
||||
If it is not provided, the provider region is used.
|
||||
|
||||
|
|
Loading…
Reference in New Issue