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

Add support for regional NEG stripping of maxUtilization based on url #3884

Merged
merged 3 commits into from
Aug 19, 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
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 -%>