Skip to content

Commit 93c9a58

Browse files
authored
Add network_pass_through_lb_traffic_policy field to google_compute_region_backend_service resource to support zonal affinity for internal passthrough network load balancer. (#15698)
1 parent a52bd6f commit 93c9a58

File tree

2 files changed

+151
-1
lines changed

2 files changed

+151
-1
lines changed

mmv1/products/compute/RegionBackendService.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,36 @@ properties:
10261026
required: true
10271027
description: |
10281028
If true, the metric data is not used for load balancing.
1029+
- name: 'networkPassThroughLbTrafficPolicy'
1030+
type: NestedObject
1031+
description: |
1032+
Configures traffic steering properties of internal passthrough Network Load Balancers.
1033+
min_version: beta
1034+
properties:
1035+
- name: 'zonalAffinity'
1036+
type: NestedObject
1037+
description: |
1038+
When configured, new connections are load balanced across healthy backend endpoints in the local zone.
1039+
properties:
1040+
- name: 'spillover'
1041+
type: Enum
1042+
description: |
1043+
This field indicates whether zonal affinity is enabled or not.
1044+
enum_values:
1045+
- 'ZONAL_AFFINITY_DISABLED'
1046+
- 'ZONAL_AFFINITY_SPILL_CROSS_ZONE'
1047+
- 'ZONAL_AFFINITY_STAY_WITHIN_ZONE'
1048+
default_value: 'ZONAL_AFFINITY_DISABLED'
1049+
min_version: beta
1050+
- name: 'spilloverRatio'
1051+
type: Double
1052+
description: |
1053+
The value of the field must be in [0, 1]. When the ratio of the count of healthy backend endpoints in a zone
1054+
to the count of backend endpoints in that same zone is equal to or above this threshold, the load balancer
1055+
distributes new connections to all healthy endpoints in the local zone only. When the ratio of the count
1056+
of healthy backend endpoints in a zone to the count of backend endpoints in that same zone is below this
1057+
threshold, the load balancer distributes all new connections to all healthy endpoints across all zones.
1058+
min_version: beta
10291059
- name: 'outlierDetection'
10301060
type: NestedObject
10311061
description: |

mmv1/third_party/terraform/services/compute/resource_compute_region_backend_service_test.go.tmpl

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,4 +2249,124 @@ resource "google_compute_health_check" "zero" {
22492249
}
22502250
}
22512251
`, serviceName, tagKey, tagValue, checkName)
2252-
}
2252+
}
2253+
2254+
{{ if ne $.TargetVersionName `ga` -}}
2255+
func TestAccComputeRegionBackendService_withNetworkPassThroughLbTrafficPolicy(t *testing.T) {
2256+
t.Parallel()
2257+
2258+
namePrefix := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
2259+
2260+
acctest.VcrTest(t, resource.TestCase{
2261+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2262+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
2263+
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t),
2264+
Steps: []resource.TestStep{
2265+
{
2266+
Config: testAccComputeRegionBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, "ZONAL_AFFINITY_DISABLED", 0.5),
2267+
},
2268+
{
2269+
ResourceName: "google_compute_region_backend_service.nptlbtp",
2270+
ImportState: true,
2271+
ImportStateVerify: true,
2272+
},
2273+
{
2274+
Config: testAccComputeRegionBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, "ZONAL_AFFINITY_SPILL_CROSS_ZONE", 0.6),
2275+
},
2276+
{
2277+
ResourceName: "google_compute_region_backend_service.nptlbtp",
2278+
ImportState: true,
2279+
ImportStateVerify: true,
2280+
},
2281+
{
2282+
Config: testAccComputeRegionBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, "ZONAL_AFFINITY_STAY_WITHIN_ZONE", 0.2),
2283+
},
2284+
{
2285+
ResourceName: "google_compute_region_backend_service.nptlbtp",
2286+
ImportState: true,
2287+
ImportStateVerify: true,
2288+
},
2289+
{
2290+
Config: testAccComputeRegionBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, "ZONAL_AFFINITY_STAY_WITHIN_ZONE", 1.001),
2291+
ExpectError: regexp.MustCompile("Must be less than or equal to 1.0"),
2292+
},
2293+
},
2294+
})
2295+
}
2296+
2297+
func testAccComputeRegionBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, spillover string, ratio float64) string {
2298+
return fmt.Sprintf(`
2299+
resource "google_compute_network" "default" {
2300+
provider = google-beta
2301+
name = "%s-network"
2302+
auto_create_subnetworks = false
2303+
}
2304+
2305+
resource "google_compute_subnetwork" "default" {
2306+
provider = google-beta
2307+
name = "%s-subnet"
2308+
ip_cidr_range = "10.10.0.0/16"
2309+
region = "us-central1"
2310+
network = google_compute_network.default.id
2311+
}
2312+
2313+
resource "google_compute_region_health_check" "default" {
2314+
provider = google-beta
2315+
name = "%s-health-check"
2316+
region = "us-central1"
2317+
tcp_health_check {
2318+
port = 80
2319+
}
2320+
}
2321+
2322+
resource "google_compute_instance_template" "default" {
2323+
provider = google-beta
2324+
name_prefix = "%s-instance-template"
2325+
machine_type = "e2-micro"
2326+
2327+
disk {
2328+
source_image = "debian-cloud/debian-11"
2329+
auto_delete = true
2330+
boot = true
2331+
}
2332+
2333+
network_interface {
2334+
network = "default"
2335+
}
2336+
}
2337+
2338+
resource "google_compute_instance_group_manager" "default" {
2339+
provider = google-beta
2340+
name = "%s-igm"
2341+
zone = "us-central1-a"
2342+
version {
2343+
instance_template = google_compute_instance_template.default.id
2344+
name = "primary"
2345+
}
2346+
base_instance_name = "%s-instance"
2347+
target_size = 1
2348+
}
2349+
2350+
resource "google_compute_region_backend_service" "nptlbtp" {
2351+
provider = google-beta
2352+
name = "%s-region-backend-service"
2353+
region = "us-central1"
2354+
load_balancing_scheme = "INTERNAL"
2355+
health_checks = [google_compute_region_health_check.default.id]
2356+
protocol = "TCP"
2357+
2358+
backend {
2359+
group = google_compute_instance_group_manager.default.instance_group
2360+
balancing_mode = "CONNECTION"
2361+
}
2362+
2363+
network_pass_through_lb_traffic_policy {
2364+
zonal_affinity {
2365+
spillover = "%s"
2366+
spillover_ratio = %f
2367+
}
2368+
}
2369+
}
2370+
`, namePrefix, namePrefix, namePrefix, namePrefix, namePrefix, namePrefix, namePrefix, spillover, ratio)
2371+
}
2372+
{{- end }}

0 commit comments

Comments
 (0)