From dbc1e33dfb5e1303d56a2748ab5d9832c8a17b4d Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 24 Jul 2020 17:56:14 -0700 Subject: [PATCH] Backend service support for internet NEG backend (#3782) (#482) * 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 --- google/compute_backend_service.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/google/compute_backend_service.go b/google/compute_backend_service.go index a3f194c3b..6d53e1bda 100644 --- a/google/compute_backend_service.go +++ b/google/compute_backend_service.go @@ -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" @@ -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 }