Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend service support for internet NEG backend #3782

Merged
merged 7 commits into from
Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1108,13 +1108,14 @@ objects:
- !ruby/object:Api::Type::Array
name: 'healthChecks'
item_type: Api::Type::String
required: true
min_size: 1
max_size: 1
description: |
slevenick marked this conversation as resolved.
Show resolved Hide resolved
The set of URLs to the HttpHealthCheck or HttpsHealthCheck resource
for health checking this BackendService. Currently at most one health
check can be specified, and a health check is required.
check can be specified.

A health check must be specified unless the backend service uses an internet NEG as a backend.

For internal load balancing, a URL to a HealthCheck resource must be specified instead.
- !ruby/object:Api::Type::Integer
Expand Down
6 changes: 6 additions & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides
vars:
backend_service_name: "backend-service"
health_check_name: "health-check"
- !ruby/object:Provider::Terraform::Examples
name: "backend_service_network_endpoint"
primary_resource_id: "default"
vars:
backend_service_name: "backend-service"
neg_name: "network-endpoint"
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: 'templates/terraform/constants/backend_service.go.erb'
encoder: 'templates/terraform/encoders/backend_service.go.erb'
Expand Down
17 changes: 17 additions & 0 deletions templates/terraform/encoders/backend_service.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,22 @@ if iapVal == nil {
obj["iap"] = iap
}

backendsRaw, ok := obj["backends"]
if !ok {
return obj, nil
}
backends := backendsRaw.([]interface{})
for _, backendRaw := range backends {
backend := backendRaw.(map[string]interface{})
backendGroup, ok := backend["group"]
if !ok {
continue
}
if strings.Contains(backendGroup.(string), "global/networkEndpointGroups") {
// Remove `max_utilization` from any backend that belongs to a global NEG. This field
// has a default value and causes API validation errors
backend["maxUtilization"] = nil
}
}

return obj, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "google_compute_global_network_endpoint_group" "external_proxy" {
name = "<%= ctx[:vars]['neg_name'] %>"
network_endpoint_type = "INTERNET_FQDN_PORT"
default_port = "443"
}

resource "google_compute_global_network_endpoint" "proxy" {
global_network_endpoint_group = google_compute_global_network_endpoint_group.external_proxy.id
fqdn = "test.example.com"
port = google_compute_global_network_endpoint_group.external_proxy.default_port
}

resource "google_compute_backend_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['backend_service_name'] %>"
enable_cdn = true
timeout_sec = 10
connection_draining_timeout_sec = 10

custom_request_headers = ["host: ${google_compute_global_network_endpoint.proxy.fqdn}"]

backend {
group = google_compute_global_network_endpoint_group.external_proxy.id
}
}