From 20f2ab5dd5f8b4fc88d17215e91a43fc8d1968cc Mon Sep 17 00:00:00 2001 From: Ty Larrabee Date: Thu, 5 Sep 2019 19:33:19 +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 | 93 +++++++++++++++++++ .../r/compute_backend_service.html.markdown | 56 ++++++++++- .../docs/r/google_project_iam.html.markdown | 2 +- 4 files changed, 147 insertions(+), 6 deletions(-) diff --git a/google/resource_compute_backend_service.go b/google/resource_compute_backend_service.go index 148af535aef..af0c28b6f0c 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", "GENERATED_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..9ac9bf4aa23 100644 --- a/google/resource_compute_backend_service_test.go +++ b/google/resource_compute_backend_service_test.go @@ -690,6 +690,99 @@ func TestAccComputeBackendService_withMaxConnectionsPerEndpoint(t *testing.T) { }) } +func testAccComputeBackendService_trafficDirector(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_trafficDirectorUpdate(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 { + 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..b001e5944b9 100644 --- a/website/docs/r/compute_backend_service.html.markdown +++ b/website/docs/r/compute_backend_service.html.markdown @@ -57,6 +57,48 @@ resource "google_compute_http_health_check" "default" { timeout_sec = 1 } ``` + +## Example Usage - Backend Service Traffic Director + + +```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" + 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 +185,16 @@ 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. + When the loadBalancingScheme is EXTERNAL, possible values are NONE, + CLIENT_IP, or GENERATED_COOKIE. You can use GENERATED_COOKIE if the + protocol is HTTP or HTTPS. + When the loadBalancingScheme is INTERNAL, possible values are NONE, + CLIENT_IP, CLIENT_IP_PROTO, or CLIENT_IP_PORT_PROTO. + When the loadBalancingScheme is INTERNAL_SELF_MANAGED, possible values + are NONE, CLIENT_IP, GENERATED_COOKIE, or (google-beta provider only) + HEADER_FIELD, or HTTP_COOKIE. * `timeout_sec` - (Optional) diff --git a/website/docs/r/google_project_iam.html.markdown b/website/docs/r/google_project_iam.html.markdown index f410c4f0224..0a12b1e1987 100644 --- a/website/docs/r/google_project_iam.html.markdown +++ b/website/docs/r/google_project_iam.html.markdown @@ -158,4 +158,4 @@ IAM audit config imports use the identifier of the resource in question and the ``` terraform import google_project_iam_audit_config.my_project "your-project-id foo.googleapis.com" -``` +``` \ No newline at end of file