From db1ea915044a34e695fe0cefb9c71eefe98eb638 Mon Sep 17 00:00:00 2001 From: Ty Larrabee Date: Mon, 16 Sep 2019 23:45:16 +0000 Subject: [PATCH] Add beta fields to BackendService to support traffic director Signed-off-by: Modular Magician --- google/resource_compute_backend_service.go | 2 +- .../resource_compute_backend_service_test.go | 155 ++++++++++++++++++ .../r/compute_backend_service.html.markdown | 76 ++++++++- 3 files changed, 228 insertions(+), 5 deletions(-) diff --git a/google/resource_compute_backend_service.go b/google/resource_compute_backend_service.go index 148af535aef..b5be159817c 100644 --- a/google/resource_compute_backend_service.go +++ b/google/resource_compute_backend_service.go @@ -294,7 +294,7 @@ func resourceComputeBackendService() *schema.Resource { Type: schema.TypeString, Computed: true, Optional: true, - ValidateFunc: validation.StringInSlice([]string{"NONE", "CLIENT_IP", "GENERATED_COOKIE", ""}, false), + ValidateFunc: validation.StringInSlice([]string{"NONE", "CLIENT_IP", "CLIENT_IP_PORT_PROTO", "CLIENT_IP_PROTO", "GENERATED_COOKIE", "HEADER_FIELD", "HTTP_COOKIE", ""}, false), }, "timeout_sec": { Type: schema.TypeInt, diff --git a/google/resource_compute_backend_service_test.go b/google/resource_compute_backend_service_test.go index abafe21e759..35049b8e77d 100644 --- a/google/resource_compute_backend_service_test.go +++ b/google/resource_compute_backend_service_test.go @@ -690,6 +690,161 @@ func TestAccComputeBackendService_withMaxConnectionsPerEndpoint(t *testing.T) { }) } +func testAccComputeBackendService_trafficDirectorBasic(serviceName, checkName string) string { + return fmt.Sprintf(` +resource "google_compute_backend_service" "foobar" { + + name = "%s" + health_checks = ["${google_compute_health_check.health_check.self_link}"] + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + locality_lb_policy = "RING_HASH" + circuit_breakers { + max_connections = 10 + } + consistent_hash { + http_cookie { + ttl { + seconds = 11 + nanos = 1234 + } + name = "mycookie" + } + } + outlier_detection { + consecutive_errors = 2 + } +} + +resource "google_compute_health_check" "health_check" { + + name = "%s" + http_health_check { + + } +} +`, serviceName, checkName) +} + +func testAccComputeBackendService_trafficDirectorUpdateBasic(serviceName, checkName string) string { + return fmt.Sprintf(` +resource "google_compute_backend_service" "foobar" { + + name = "%s" + health_checks = ["${google_compute_health_check.health_check.self_link}"] + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + locality_lb_policy = "RANDOM" + circuit_breakers { + max_connections = 10 + } + outlier_detection { + consecutive_errors = 2 + } +} + +resource "google_compute_health_check" "health_check" { + + name = "%s" + http_health_check { + + } +} +`, serviceName, checkName) +} + +func testAccComputeBackendService_trafficDirectorFull(serviceName, checkName string) string { + return fmt.Sprintf(` +resource "google_compute_backend_service" "foobar" { + + name = "%s" + health_checks = ["${google_compute_health_check.health_check.self_link}"] + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + locality_lb_policy = "MAGLEV" + circuit_breakers { + max_connections = 10 + } + consistent_hash { + http_cookie { + ttl { + seconds = 11 + nanos = 1234 + } + name = "mycookie" + } + } + outlier_detection { + consecutive_errors = 2 + } +} + +resource "google_compute_health_check" "health_check" { + + name = "%s" + http_health_check { + + } +} +`, serviceName, checkName) +} + +func testAccComputeBackendService_trafficDirectorUpdateFull(serviceName, checkName string) string { + return fmt.Sprintf(` +resource "google_compute_backend_service" "foobar" { + + name = "%s" + health_checks = ["${google_compute_health_check.health_check.self_link}"] + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + locality_lb_policy = "MAGLEV" + circuit_breakers { + connect_timeout { + seconds = 3 + nanos = 4 + } + max_connections = 11 + max_requests_per_connection = 12 + max_pending_requests = 13 + max_requests = 14 + max_retries = 15 + } + consistent_hash { + http_cookie { + ttl { + seconds = 12 + } + name = "mycookie2" + path = "mycookie2/path" + } + minimum_ring_size = 16 + } + outlier_detection { + base_ejection_time { + seconds = 0 + nanos = 5 + } + consecutive_errors = 1 + consecutive_gateway_failure = 3 + enforcing_consecutive_errors = 4 + enforcing_consecutive_gateway_failure = 5 + enforcing_success_rate = 6 + interval { + seconds = 7 + } + max_ejection_percent = 99 + success_rate_minimum_hosts = 98 + success_rate_request_volume = 97 + success_rate_stdev_factor = 1800 + } +} + +resource "google_compute_health_check" "health_check" { + + name = "%s" + http_health_check { + + } +} +`, serviceName, checkName) +} + func testAccComputeBackendService_basic(serviceName, checkName string) string { return fmt.Sprintf(` resource "google_compute_backend_service" "foobar" { diff --git a/website/docs/r/compute_backend_service.html.markdown b/website/docs/r/compute_backend_service.html.markdown index 042855ce1ed..d2c3c8c97af 100644 --- a/website/docs/r/compute_backend_service.html.markdown +++ b/website/docs/r/compute_backend_service.html.markdown @@ -57,6 +57,76 @@ resource "google_compute_http_health_check" "default" { timeout_sec = 1 } ``` + +## Example Usage - Backend Service Traffic Director Round Robin + + +```hcl +resource "google_compute_backend_service" "default" { + provider = "google-beta" + + name = "backend-service" + health_checks = ["${google_compute_health_check.health_check.self_link}"] + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + locality_lb_policy = "ROUND_ROBIN" +} + +resource "google_compute_health_check" "health_check" { + provider = "google-beta" + + name = "health-check" + http_health_check { + + } +} +``` + +## Example Usage - Backend Service Traffic Director Ring Hash + + +```hcl +resource "google_compute_backend_service" "default" { + provider = "google-beta" + + name = "backend-service" + health_checks = ["${google_compute_health_check.health_check.self_link}"] + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + locality_lb_policy = "RING_HASH" + session_affinity = "HTTP_COOKIE" + circuit_breakers { + max_connections = 10 + } + consistent_hash { + http_cookie { + ttl { + seconds = 11 + nanos = 1111 + } + name = "mycookie" + } + } + outlier_detection { + consecutive_errors = 2 + } +} + +resource "google_compute_health_check" "health_check" { + provider = "google-beta" + + name = "health-check" + http_health_check { + + } +} +``` ## Argument Reference @@ -143,10 +213,8 @@ The following arguments are supported: * `session_affinity` - (Optional) - Type of session affinity to use. The default is NONE. - When the load balancing scheme is EXTERNAL, can be NONE, CLIENT_IP, or - GENERATED_COOKIE. - When the protocol is UDP, this field is not used. + Type of session affinity to use. The default is NONE. Session affinity is + not applicable if the protocol is UDP. * `timeout_sec` - (Optional)