Skip to content

Commit 4846fa0

Browse files
Make Backend Service Custom Metrics tests available in ga (#13274) (#21865)
[upstream:38449e2c5533dd6bce0dbf9b0794b115cc57309f] Signed-off-by: Modular Magician <[email protected]>
1 parent 8bc836f commit 4846fa0

6 files changed

+304
-9
lines changed

.changelog/13274.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
```release-note:none
2+
```

google/services/compute/resource_compute_backend_service_generated_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,86 @@ resource "google_compute_backend_service" "default" {
430430
`, context)
431431
}
432432

433+
func TestAccComputeBackendService_backendServiceCustomMetricsExample(t *testing.T) {
434+
t.Parallel()
435+
436+
context := map[string]interface{}{
437+
"random_suffix": acctest.RandString(t, 10),
438+
}
439+
440+
acctest.VcrTest(t, resource.TestCase{
441+
PreCheck: func() { acctest.AccTestPreCheck(t) },
442+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
443+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
444+
Steps: []resource.TestStep{
445+
{
446+
Config: testAccComputeBackendService_backendServiceCustomMetricsExample(context),
447+
},
448+
{
449+
ResourceName: "google_compute_backend_service.default",
450+
ImportState: true,
451+
ImportStateVerify: true,
452+
ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret", "security_settings.0.aws_v4_authentication.0.access_key"},
453+
},
454+
},
455+
})
456+
}
457+
458+
func testAccComputeBackendService_backendServiceCustomMetricsExample(context map[string]interface{}) string {
459+
return acctest.Nprintf(`
460+
resource "google_compute_network" "default" {
461+
name = "network%{random_suffix}"
462+
}
463+
464+
// Zonal NEG with GCE_VM_IP_PORT
465+
resource "google_compute_network_endpoint_group" "default" {
466+
name = "tf-test-network-endpoint%{random_suffix}"
467+
network = google_compute_network.default.id
468+
default_port = "90"
469+
zone = "us-central1-a"
470+
network_endpoint_type = "GCE_VM_IP_PORT"
471+
}
472+
473+
resource "google_compute_backend_service" "default" {
474+
name = "tf-test-backend-service%{random_suffix}"
475+
health_checks = [google_compute_health_check.default.id]
476+
477+
# WEIGHTED_ROUND_ROBIN and CUSTOM_METRICS require EXTERNAL_MANAGED.
478+
load_balancing_scheme = "EXTERNAL_MANAGED"
479+
locality_lb_policy = "WEIGHTED_ROUND_ROBIN"
480+
custom_metrics {
481+
name = "orca.application_utilization"
482+
# At least one metric should be not dry_run.
483+
dry_run = false
484+
}
485+
backend {
486+
group = google_compute_network_endpoint_group.default.id
487+
balancing_mode = "CUSTOM_METRICS"
488+
custom_metrics {
489+
name = "orca.cpu_utilization"
490+
max_utilization = 0.9
491+
dry_run = true
492+
}
493+
custom_metrics {
494+
name = "orca.named_metrics.foo"
495+
# At least one metric should be not dry_run.
496+
dry_run = false
497+
}
498+
}
499+
}
500+
501+
resource "google_compute_health_check" "default" {
502+
name = "tf-test-health-check%{random_suffix}"
503+
timeout_sec = 1
504+
check_interval_sec = 1
505+
506+
tcp_health_check {
507+
port = "80"
508+
}
509+
}
510+
`, context)
511+
}
512+
433513
func TestAccComputeBackendService_backendServiceTlsSettingsExample(t *testing.T) {
434514
t.Parallel()
435515

google/services/compute/resource_compute_backend_service_test.go

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,3 +2087,149 @@ resource "google_network_security_client_tls_policy" "foobar2" {
20872087
}
20882088
`, randomSuffix, randomSuffix, randomSuffix)
20892089
}
2090+
2091+
func TestAccComputeBackendService_backendServiceCustomMetrics_update(t *testing.T) {
2092+
t.Parallel()
2093+
2094+
context := map[string]interface{}{
2095+
"random_suffix": acctest.RandString(t, 10),
2096+
}
2097+
2098+
acctest.VcrTest(t, resource.TestCase{
2099+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2100+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2101+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
2102+
Steps: []resource.TestStep{
2103+
{
2104+
Config: testAccComputeBackendService_backendServiceCustomMetrics_full(context),
2105+
},
2106+
{
2107+
ResourceName: "google_compute_backend_service.default",
2108+
ImportState: true,
2109+
ImportStateVerify: true,
2110+
ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret", "security_settings.0.aws_v4_authentication.0.access_key"},
2111+
},
2112+
{
2113+
Config: testAccComputeBackendService_backendServiceCustomMetrics_update(context),
2114+
},
2115+
{
2116+
ResourceName: "google_compute_backend_service.default",
2117+
ImportState: true,
2118+
ImportStateVerify: true,
2119+
ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret", "security_settings.0.aws_v4_authentication.0.access_key"},
2120+
},
2121+
},
2122+
})
2123+
}
2124+
2125+
func testAccComputeBackendService_backendServiceCustomMetrics_full(context map[string]interface{}) string {
2126+
return acctest.Nprintf(`
2127+
resource "google_compute_network" "default" {
2128+
name = "network%{random_suffix}"
2129+
}
2130+
2131+
// Zonal NEG with GCE_VM_IP_PORT
2132+
resource "google_compute_network_endpoint_group" "default" {
2133+
name = "tf-test-network-endpoint%{random_suffix}"
2134+
network = google_compute_network.default.id
2135+
default_port = "90"
2136+
zone = "us-central1-a"
2137+
network_endpoint_type = "GCE_VM_IP_PORT"
2138+
}
2139+
2140+
resource "google_compute_backend_service" "default" {
2141+
name = "tf-test-backend-service%{random_suffix}"
2142+
health_checks = [google_compute_health_check.default.id]
2143+
2144+
# WEIGHTED_ROUND_ROBIN and CUSTOM_METRICS require EXTERNAL_MANAGED.
2145+
load_balancing_scheme = "EXTERNAL_MANAGED"
2146+
locality_lb_policy = "WEIGHTED_ROUND_ROBIN"
2147+
custom_metrics {
2148+
name = "orca.application_utilization"
2149+
# At least one metric should be not dry_run.
2150+
dry_run = false
2151+
}
2152+
backend {
2153+
group = google_compute_network_endpoint_group.default.id
2154+
balancing_mode = "CUSTOM_METRICS"
2155+
custom_metrics {
2156+
name = "orca.cpu_utilization"
2157+
max_utilization = 0.9
2158+
dry_run = true
2159+
}
2160+
custom_metrics {
2161+
name = "orca.named_metrics.foo"
2162+
max_utilization = 0.9
2163+
# At least one metric should be not dry_run.
2164+
dry_run = false
2165+
}
2166+
}
2167+
}
2168+
2169+
resource "google_compute_health_check" "default" {
2170+
name = "tf-test-health-check%{random_suffix}"
2171+
timeout_sec = 1
2172+
check_interval_sec = 1
2173+
2174+
tcp_health_check {
2175+
port = "80"
2176+
}
2177+
}
2178+
`, context)
2179+
}
2180+
2181+
func testAccComputeBackendService_backendServiceCustomMetrics_update(context map[string]interface{}) string {
2182+
return acctest.Nprintf(`
2183+
resource "google_compute_network" "default" {
2184+
name = "network%{random_suffix}"
2185+
}
2186+
2187+
// Zonal NEG with GCE_VM_IP_PORT
2188+
resource "google_compute_network_endpoint_group" "default" {
2189+
name = "tf-test-network-endpoint%{random_suffix}"
2190+
network = google_compute_network.default.id
2191+
default_port = "90"
2192+
zone = "us-central1-a"
2193+
network_endpoint_type = "GCE_VM_IP_PORT"
2194+
}
2195+
2196+
resource "google_compute_backend_service" "default" {
2197+
name = "tf-test-backend-service%{random_suffix}"
2198+
health_checks = [google_compute_health_check.default.id]
2199+
2200+
# WEIGHTED_ROUND_ROBIN and CUSTOM_METRICS require EXTERNAL_MANAGED.
2201+
load_balancing_scheme = "EXTERNAL_MANAGED"
2202+
locality_lb_policy = "WEIGHTED_ROUND_ROBIN"
2203+
custom_metrics {
2204+
name = "orca.application_utilization"
2205+
# Change dry_run from false to true.
2206+
dry_run = true
2207+
}
2208+
custom_metrics {
2209+
# Add new metric.
2210+
name = "orca.named_metrics.zebra"
2211+
dry_run = false
2212+
}
2213+
backend {
2214+
group = google_compute_network_endpoint_group.default.id
2215+
balancing_mode = "CUSTOM_METRICS"
2216+
custom_metrics {
2217+
name = "orca.named_metrics.foo"
2218+
# Remove max_utilization.
2219+
dry_run = false
2220+
}
2221+
# Remove existing metric "orca.named_metrics.foo".
2222+
}
2223+
}
2224+
2225+
resource "google_compute_health_check" "default" {
2226+
name = "tf-test-health-check%{random_suffix}"
2227+
timeout_sec = 1
2228+
check_interval_sec = 1
2229+
2230+
tcp_health_check {
2231+
port = "80"
2232+
}
2233+
}
2234+
`, context)
2235+
}

google/services/compute/resource_compute_region_backend_service_generated_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,82 @@ resource "google_compute_region_health_check" "health_check" {
420420
`, context)
421421
}
422422

423+
func TestAccComputeRegionBackendService_regionBackendServiceIlbCustomMetricsExample(t *testing.T) {
424+
t.Parallel()
425+
426+
context := map[string]interface{}{
427+
"random_suffix": acctest.RandString(t, 10),
428+
}
429+
430+
acctest.VcrTest(t, resource.TestCase{
431+
PreCheck: func() { acctest.AccTestPreCheck(t) },
432+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
433+
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t),
434+
Steps: []resource.TestStep{
435+
{
436+
Config: testAccComputeRegionBackendService_regionBackendServiceIlbCustomMetricsExample(context),
437+
},
438+
{
439+
ResourceName: "google_compute_region_backend_service.default",
440+
ImportState: true,
441+
ImportStateVerify: true,
442+
ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret", "network", "region"},
443+
},
444+
},
445+
})
446+
}
447+
448+
func testAccComputeRegionBackendService_regionBackendServiceIlbCustomMetricsExample(context map[string]interface{}) string {
449+
return acctest.Nprintf(`
450+
resource "google_compute_network" "default" {
451+
name = "network%{random_suffix}"
452+
}
453+
454+
// Zonal NEG with GCE_VM_IP_PORT
455+
resource "google_compute_network_endpoint_group" "default" {
456+
name = "tf-test-network-endpoint%{random_suffix}"
457+
network = google_compute_network.default.id
458+
default_port = "90"
459+
zone = "us-central1-a"
460+
network_endpoint_type = "GCE_VM_IP_PORT"
461+
}
462+
463+
resource "google_compute_region_backend_service" "default" {
464+
region = "us-central1"
465+
name = "tf-test-region-service%{random_suffix}"
466+
health_checks = [google_compute_health_check.health_check.id]
467+
load_balancing_scheme = "INTERNAL_MANAGED"
468+
locality_lb_policy = "WEIGHTED_ROUND_ROBIN"
469+
custom_metrics {
470+
name = "orca.application_utilization"
471+
# At least one metric should be not dry_run.
472+
dry_run = false
473+
}
474+
backend {
475+
group = google_compute_network_endpoint_group.default.id
476+
balancing_mode = "CUSTOM_METRICS"
477+
custom_metrics {
478+
name = "orca.cpu_utilization"
479+
max_utilization = 0.9
480+
dry_run = true
481+
}
482+
custom_metrics {
483+
name = "orca.named_metrics.foo"
484+
# At least one metric should be not dry_run.
485+
dry_run = false
486+
}
487+
}
488+
}
489+
490+
resource "google_compute_health_check" "health_check" {
491+
name = "tf-test-rbs-health-check%{random_suffix}"
492+
http_health_check {
493+
port = 80
494+
}
495+
}
496+
`, context)
497+
}
498+
423499
func testAccCheckComputeRegionBackendServiceDestroyProducer(t *testing.T) func(s *terraform.State) error {
424500
return func(s *terraform.State) error {
425501
for name, rs := range s.RootModule().Resources {

website/docs/r/compute_backend_service.html.markdown

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,11 @@ resource "google_compute_backend_service" "default" {
422422

423423
```hcl
424424
resource "google_compute_network" "default" {
425-
provider = google-beta
426425
name = "network"
427426
}
428427
429428
// Zonal NEG with GCE_VM_IP_PORT
430429
resource "google_compute_network_endpoint_group" "default" {
431-
provider = google-beta
432430
name = "network-endpoint"
433431
network = google_compute_network.default.id
434432
default_port = "90"
@@ -437,7 +435,6 @@ resource "google_compute_network_endpoint_group" "default" {
437435
}
438436
439437
resource "google_compute_backend_service" "default" {
440-
provider = google-beta
441438
name = "backend-service"
442439
health_checks = [google_compute_health_check.default.id]
443440
@@ -466,7 +463,6 @@ resource "google_compute_backend_service" "default" {
466463
}
467464
468465
resource "google_compute_health_check" "default" {
469-
provider = google-beta
470466
name = "health-check"
471467
timeout_sec = 1
472468
check_interval_sec = 1

website/docs/r/compute_region_backend_service.html.markdown

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,11 @@ resource "google_compute_region_health_check" "health_check" {
438438

439439
```hcl
440440
resource "google_compute_network" "default" {
441-
provider = google-beta
442441
name = "network"
443442
}
444443
445444
// Zonal NEG with GCE_VM_IP_PORT
446445
resource "google_compute_network_endpoint_group" "default" {
447-
provider = google-beta
448446
name = "network-endpoint"
449447
network = google_compute_network.default.id
450448
default_port = "90"
@@ -453,8 +451,6 @@ resource "google_compute_network_endpoint_group" "default" {
453451
}
454452
455453
resource "google_compute_region_backend_service" "default" {
456-
provider = google-beta
457-
458454
region = "us-central1"
459455
name = "region-service"
460456
health_checks = [google_compute_health_check.health_check.id]
@@ -482,7 +478,6 @@ resource "google_compute_region_backend_service" "default" {
482478
}
483479
484480
resource "google_compute_health_check" "health_check" {
485-
provider = google-beta
486481
name = "rbs-health-check"
487482
http_health_check {
488483
port = 80

0 commit comments

Comments
 (0)