Skip to content

Commit

Permalink
Add beta fields to BackendService to support traffic director
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
Ty Larrabee authored and modular-magician committed Sep 18, 2019
1 parent bc7726a commit ebb6862
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 5 deletions.
2 changes: 1 addition & 1 deletion google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
155 changes: 155 additions & 0 deletions google/resource_compute_backend_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
76 changes: 72 additions & 4 deletions website/docs/r/compute_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,76 @@ resource "google_compute_http_health_check" "default" {
timeout_sec = 1
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=backend_service_traffic_director_round_robin&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## 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 {
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=backend_service_traffic_director_ring_hash&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## 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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ebb6862

Please sign in to comment.