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 <magic-modules@google.com>
  • Loading branch information
Ty Larrabee authored and modular-magician committed Sep 5, 2019
1 parent 1246621 commit 20f2ab5
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 6 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", "GENERATED_COOKIE", ""}, false),
},
"timeout_sec": {
Type: schema.TypeInt,
Expand Down
93 changes: 93 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,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" {
Expand Down
56 changes: 52 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,48 @@ 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%2Fgit.luolix.top%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=backend_service_traffic_director&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


```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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/google_project_iam.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
```

0 comments on commit 20f2ab5

Please sign in to comment.