Skip to content

Commit

Permalink
Add support for regional NEG stripping of maxUtilization based on url (
Browse files Browse the repository at this point in the history
…#3884)

* Add support for regional NEG stripping of maxUtilization based on url

* Pr feedback

* Consolidate regexes
  • Loading branch information
slevenick authored Aug 19, 2020
1 parent 0b984e8 commit bf5596c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
9 changes: 7 additions & 2 deletions templates/terraform/encoders/backend_service.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ for _, backendRaw := range backends {
if !ok {
continue
}
if strings.Contains(backendGroup.(string), "global/networkEndpointGroups") {
// Remove `max_utilization` from any backend that belongs to a global NEG. This field

match, err := regexp.MatchString("(?:global|regions/[^/]+)/networkEndpointGroups", backendGroup.(string))
if err != nil {
return nil, err
}
if match {
// Remove `max_utilization` from any backend that belongs to a serverless NEG. This field
// has a default value and causes API validation errors
backend["maxUtilization"] = nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,30 @@ func TestAccComputeBackendService_trafficDirectorUpdateFull(t *testing.T) {
}
<% end -%>
<% unless version == 'ga' -%>
func TestAccComputeBackendService_regionNegBackend(t *testing.T) {
t.Parallel()

suffix := randString(t, 10)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeBackendService_regionNegBackend(suffix),
},
{
ResourceName: "google_compute_backend_service.backend",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
<% end -%>

func testAccComputeBackendService_trafficDirectorBasic(serviceName, checkName string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
Expand Down Expand Up @@ -1508,3 +1532,47 @@ resource "google_compute_http_health_check" "zero" {
}
`, serviceName, sampleRate, checkName)
}

<% unless version == 'ga' -%>
func testAccComputeBackendService_regionNegBackend(suffix string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "backend" {
name = "tf-test-backend%s"
enable_cdn = true
connection_draining_timeout_sec = 10

backend {
group = google_compute_region_network_endpoint_group.cloudrun_neg.id
}
}

resource "google_compute_region_network_endpoint_group" "cloudrun_neg" {
name = "tf-test-neg%s"
network_endpoint_type = "SERVERLESS"
region = "us-central1"
cloud_run {
service = google_cloud_run_service.cloudrun_neg.name
}
}

resource "google_cloud_run_service" "cloudrun_neg" {
name = "tf-test-cr%s"
location = "us-central1"

template {
spec {
containers {
image = "gcr.io/cloudrun/hello"
}
}
}

traffic {
percent = 100
latest_revision = true
}
}

`, suffix, suffix, suffix)
}
<% end -%>

0 comments on commit bf5596c

Please sign in to comment.