Skip to content

Commit

Permalink
Merge pull request #11228 from cblecker/rbs-sessionaffinity
Browse files Browse the repository at this point in the history
provider/google: Add support for session_affinity to google_compute_region_backend_service
  • Loading branch information
danawillow authored Jan 18, 2017
2 parents 51e1a15 + 73bd728 commit 006e9b1
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
54 changes: 50 additions & 4 deletions vendor/google.golang.org/api/compute/v1/compute-api.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 006e9b1

Please sign in to comment.