Skip to content

Commit

Permalink
Backend service support for internet NEG backend (#3782) (#482)
Browse files Browse the repository at this point in the history
* Add ability to set global network endpoint group as backend for backend service. Make health_checks optional

* PR fixes

* Add encoder to remove max_utilization when neg backend

* Check for global NEG in group to remove max_utilization

* Add another nil check

* Spacing

* Docs fix

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 25, 2020
1 parent 7cc477d commit dbc1e33
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions google/compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"log"
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -317,6 +318,24 @@ func resourceComputeBackendServiceEncoder(d TerraformResourceData, meta interfac
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
}

Expand Down

0 comments on commit dbc1e33

Please sign in to comment.