Skip to content

Commit 50c3e4d

Browse files
Cezarus27BBBmau
authored andcommitted
Feature gap: Add missed fields to BackendService and RegionBackendService (GoogleCloudPlatform#13821)
Signed-off-by: Cezary Sobczak <Cezary.Sobczak@infogain.com>
1 parent 813ad42 commit 50c3e4d

File tree

6 files changed

+254
-2
lines changed

6 files changed

+254
-2
lines changed

mmv1/products/compute/BackendService.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ examples:
142142
vars:
143143
url_map_name: 'url_map'
144144
exclude_test: true
145+
- name: 'backend_service_dynamic_forwarding'
146+
primary_resource_id: 'default'
147+
min_version: 'beta'
148+
vars:
149+
backend_service_name: 'backend-service'
145150
parameters:
146151
properties:
147152
- name: 'affinityCookieTtlSec'
@@ -1618,3 +1623,52 @@ properties:
16181623
Span of time that's a fraction of a second at nanosecond resolution.
16191624
Durations less than one second are represented with a 0 seconds field and a positive nanos field.
16201625
Must be from 0 to 999,999,999 inclusive.
1626+
- name: 'networkPassThroughLbTrafficPolicy'
1627+
type: NestedObject
1628+
description: |
1629+
Configures traffic steering properties of internal passthrough Network Load Balancers.
1630+
min_version: beta
1631+
properties:
1632+
- name: 'zonalAffinity'
1633+
type: NestedObject
1634+
description: |
1635+
When configured, new connections are load balanced across healthy backend endpoints in the local zone.
1636+
properties:
1637+
- name: 'spillover'
1638+
type: Enum
1639+
description: |
1640+
This field indicates whether zonal affinity is enabled or not.
1641+
enum_values:
1642+
- 'ZONAL_AFFINITY_DISABLED'
1643+
- 'ZONAL_AFFINITY_SPILL_CROSS_ZONE'
1644+
- 'ZONAL_AFFINITY_STAY_WITHIN_ZONE'
1645+
default_value: 'ZONAL_AFFINITY_DISABLED'
1646+
min_version: beta
1647+
- name: 'spilloverRatio'
1648+
type: Double
1649+
description: |
1650+
The value of the field must be in [0, 1]. When the ratio of the count of healthy backend endpoints in a zone
1651+
to the count of backend endpoints in that same zone is equal to or above this threshold, the load balancer
1652+
distributes new connections to all healthy endpoints in the local zone only. When the ratio of the count
1653+
of healthy backend endpoints in a zone to the count of backend endpoints in that same zone is below this
1654+
threshold, the load balancer distributes all new connections to all healthy endpoints across all zones.
1655+
min_version: beta
1656+
- name: 'dynamicForwarding'
1657+
type: NestedObject
1658+
description: |
1659+
Dynamic forwarding configuration. This field is used to configure the backend service with dynamic forwarding
1660+
feature which together with Service Extension allows customized and complex routing logic.
1661+
min_version: beta
1662+
properties:
1663+
- name: 'ipPortSelection'
1664+
type: NestedObject
1665+
description: |
1666+
IP:PORT based dynamic forwarding configuration.
1667+
min_version: beta
1668+
properties:
1669+
- name: 'enabled'
1670+
type: Boolean
1671+
min_version: beta
1672+
description: |
1673+
A boolean flag enabling IP:PORT based dynamic forwarding.
1674+
immutable: true

mmv1/products/compute/RegionBackendService.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ examples:
139139
instance_group_name: 'instance_group'
140140
network_name: 'network'
141141
exclude_test: true
142+
- name: 'region_backend_service_dynamic_forwarding'
143+
primary_resource_id: 'default'
144+
min_version: 'beta'
145+
vars:
146+
region_backend_service_name: 'region-service'
142147
parameters:
143148
- name: 'region'
144149
type: ResourceRef
@@ -1438,3 +1443,32 @@ properties:
14381443
required: true
14391444
enum_values:
14401445
- 'CONSISTENT_HASH_SUBSETTING'
1446+
- name: 'subsetSize'
1447+
type: Integer
1448+
description: |
1449+
The number of backends per backend group assigned to each proxy instance or each service mesh client.
1450+
An input parameter to the CONSISTENT_HASH_SUBSETTING algorithm. Can only be set if policy is set to
1451+
CONSISTENT_HASH_SUBSETTING. Can only be set if load balancing scheme is INTERNAL_MANAGED or INTERNAL_SELF_MANAGED.
1452+
subsetSize is optional for Internal HTTP(S) load balancing and required for Traffic Director.
1453+
If you do not provide this value, Cloud Load Balancing will calculate it dynamically to optimize the number
1454+
of proxies/clients visible to each backend and vice versa.
1455+
Must be greater than 0. If subsetSize is larger than the number of backends/endpoints, then subsetting is disabled.
1456+
- name: 'dynamicForwarding'
1457+
type: NestedObject
1458+
description: |
1459+
Dynamic forwarding configuration. This field is used to configure the backend service with dynamic forwarding
1460+
feature which together with Service Extension allows customized and complex routing logic.
1461+
min_version: beta
1462+
properties:
1463+
- name: 'ipPortSelection'
1464+
type: NestedObject
1465+
description: |
1466+
IP:PORT based dynamic forwarding configuration.
1467+
min_version: beta
1468+
properties:
1469+
- name: 'enabled'
1470+
type: Boolean
1471+
min_version: beta
1472+
description: |
1473+
A boolean flag enabling IP:PORT based dynamic forwarding.
1474+
immutable: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "google_compute_backend_service" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
name = "{{index $.Vars "backend_service_name"}}"
4+
load_balancing_scheme = "INTERNAL_MANAGED"
5+
dynamic_forwarding {
6+
ip_port_selection {
7+
enabled = true
8+
}
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "google_compute_region_backend_service" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
name = "{{index $.Vars "region_backend_service_name"}}"
4+
region = "us-central1"
5+
load_balancing_scheme = "EXTERNAL_MANAGED"
6+
dynamic_forwarding {
7+
ip_port_selection {
8+
enabled = true
9+
}
10+
}
11+
}

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

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package compute_test
22

33
import (
44
"fmt"
5+
{{ if ne $.TargetVersionName `ga` -}}
6+
"regexp"
7+
{{- end }}
58
"testing"
69

710
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -1116,6 +1119,50 @@ func TestAccComputeBackendService_backendServiceMaxDuration(t *testing.T) {
11161119
})
11171120
}
11181121

1122+
{{ if ne $.TargetVersionName `ga` -}}
1123+
func TestAccComputeBackendService_withNetworkPassThroughLbTrafficPolicy(t *testing.T) {
1124+
t.Parallel()
1125+
1126+
namePrefix := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
1127+
1128+
acctest.VcrTest(t, resource.TestCase{
1129+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1130+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
1131+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
1132+
Steps: []resource.TestStep{
1133+
{
1134+
Config: testAccComputeBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, "ZONAL_AFFINITY_DISABLED", 0.5),
1135+
},
1136+
{
1137+
ResourceName: "google_compute_backend_service.nptlbtp",
1138+
ImportState: true,
1139+
ImportStateVerify: true,
1140+
},
1141+
{
1142+
Config: testAccComputeBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, "ZONAL_AFFINITY_SPILL_CROSS_ZONE", 0.6),
1143+
},
1144+
{
1145+
ResourceName: "google_compute_backend_service.nptlbtp",
1146+
ImportState: true,
1147+
ImportStateVerify: true,
1148+
},
1149+
{
1150+
Config: testAccComputeBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, "ZONAL_AFFINITY_STAY_WITHIN_ZONE", 0.2),
1151+
},
1152+
{
1153+
ResourceName: "google_compute_backend_service.nptlbtp",
1154+
ImportState: true,
1155+
ImportStateVerify: true,
1156+
},
1157+
{
1158+
Config: testAccComputeBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, "ZONAL_AFFINITY_STAY_WITHIN_ZONE", 1.001),
1159+
ExpectError: regexp.MustCompile("Must be less than or equal to 1.0"),
1160+
},
1161+
},
1162+
})
1163+
}
1164+
{{- end }}
1165+
11191166
func testAccComputeBackendService_trafficDirectorBasic(serviceName, checkName string) string {
11201167
return fmt.Sprintf(`
11211168
resource "google_compute_backend_service" "foobar" {
@@ -2867,3 +2914,61 @@ resource "google_compute_http_health_check" "zero" {
28672914
}
28682915
`, serviceName, description, percentage, checkName)
28692916
}
2917+
2918+
{{ if ne $.TargetVersionName `ga` -}}
2919+
func testAccComputeBackendService_withNetworkPassThroughLbTrafficPolicy(namePrefix, spillover string, ratio float64) string {
2920+
return fmt.Sprintf(`
2921+
resource "google_compute_backend_service" "nptlbtp" {
2922+
provider = google-beta
2923+
name = "%s-backend"
2924+
description = "Hello World 1234"
2925+
protocol = "TCP"
2926+
health_checks = [google_compute_health_check.default.self_link]
2927+
2928+
backend {
2929+
group = google_compute_network_endpoint_group.lb-neg.self_link
2930+
balancing_mode = "CONNECTION"
2931+
max_connections_per_endpoint = 1000
2932+
}
2933+
2934+
network_pass_through_lb_traffic_policy {
2935+
zonal_affinity {
2936+
spillover = "%s"
2937+
spillover_ratio = %f
2938+
}
2939+
}
2940+
}
2941+
2942+
resource "google_compute_network_endpoint_group" "lb-neg" {
2943+
provider = google-beta
2944+
name = "%s-neg"
2945+
network = google_compute_network.default.self_link
2946+
subnetwork = google_compute_subnetwork.default.self_link
2947+
default_port = "90"
2948+
zone = "us-central1-a"
2949+
}
2950+
2951+
resource "google_compute_network" "default" {
2952+
provider = google-beta
2953+
name = "%s-network"
2954+
auto_create_subnetworks = false
2955+
}
2956+
2957+
resource "google_compute_subnetwork" "default" {
2958+
provider = google-beta
2959+
name = "%s-subnetwork"
2960+
ip_cidr_range = "10.0.0.0/16"
2961+
region = "us-central1"
2962+
network = google_compute_network.default.self_link
2963+
}
2964+
2965+
resource "google_compute_health_check" "default" {
2966+
provider = google-beta
2967+
name = "%s-health-check"
2968+
tcp_health_check {
2969+
port = "110"
2970+
}
2971+
}
2972+
`, namePrefix, spillover, ratio, namePrefix, namePrefix, namePrefix, namePrefix)
2973+
}
2974+
{{- end }}

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,18 @@ func TestAccComputeRegionBackendService_subsettingUpdate(t *testing.T) {
385385
ImportState: true,
386386
ImportStateVerify: true,
387387
},
388+
{
389+
Config: testAccComputeRegionBackendService_imlbWithSubsettingSubsetSize(backendName, checkName, 3),
390+
},
391+
{
392+
ResourceName: "google_compute_region_backend_service.foobar",
393+
ImportState: true,
394+
ImportStateVerify: true,
395+
},
396+
{
397+
Config: testAccComputeRegionBackendService_imlbWithSubsettingSubsetSize(backendName, checkName, -1),
398+
ExpectError: regexp.MustCompile("Must be greater than or equal to 1"),
399+
},
388400
},
389401
})
390402
}
@@ -1310,7 +1322,7 @@ resource "google_compute_region_backend_service" "foobar" {
13101322
name = "%s"
13111323
health_checks = [google_compute_health_check.health_check.self_link]
13121324
protocol = "TCP"
1313-
load_balancing_scheme = "INTERNAL"
1325+
load_balancing_scheme = "INTERNAL"
13141326
subsetting {
13151327
policy = "CONSISTENT_HASH_SUBSETTING"
13161328
}
@@ -1331,7 +1343,7 @@ resource "google_compute_region_backend_service" "foobar" {
13311343
name = "%s"
13321344
health_checks = [google_compute_health_check.health_check.self_link]
13331345
protocol = "TCP"
1334-
load_balancing_scheme = "INTERNAL"
1346+
load_balancing_scheme = "INTERNAL"
13351347
}
13361348
13371349
resource "google_compute_health_check" "health_check" {
@@ -1342,6 +1354,32 @@ resource "google_compute_health_check" "health_check" {
13421354
}
13431355
`, serviceName, checkName)
13441356
}
1357+
1358+
func testAccComputeRegionBackendService_imlbWithSubsettingSubsetSize(serviceName, checkName string, subsetSize int64) string {
1359+
return fmt.Sprintf(`
1360+
resource "google_compute_region_backend_service" "foobar" {
1361+
name = "%s"
1362+
health_checks = [google_compute_region_health_check.zero.self_link]
1363+
protocol = "HTTP"
1364+
load_balancing_scheme = "INTERNAL_MANAGED"
1365+
subsetting {
1366+
policy = "CONSISTENT_HASH_SUBSETTING"
1367+
subset_size = %d
1368+
}
1369+
}
1370+
1371+
resource "google_compute_region_health_check" "zero" {
1372+
name = "%s"
1373+
region = "us-central1"
1374+
check_interval_sec = 1
1375+
timeout_sec = 1
1376+
1377+
http_health_check {
1378+
port = 80
1379+
}
1380+
}
1381+
`, serviceName, subsetSize, checkName)
1382+
}
13451383
{{- end }}
13461384

13471385
{{ if ne $.TargetVersionName `ga` -}}

0 commit comments

Comments
 (0)