Skip to content

Commit 68c4f9a

Browse files
Add region_backend_service portName (#3265) (#2048)
* Add region_backend_service portName * add port_name attribute to test cases * add update from http to https for ilbUpdates Co-authored-by: cynful <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: cynful <[email protected]>
1 parent f0e5896 commit 68c4f9a

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

.changelog/3265.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
Add region_backend_service portName parameter
3+
```

google-beta/resource_compute_region_backend_service.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,18 @@ runtime value should be 1900. Defaults to 1900.`,
628628
},
629629
},
630630
},
631+
"port_name": {
632+
Type: schema.TypeString,
633+
Computed: true,
634+
Optional: true,
635+
Description: `A named port on a backend instance group representing the port for
636+
communication to the backend VMs in that group. Required when the
637+
loadBalancingScheme is EXTERNAL, INTERNAL_MANAGED, or INTERNAL_SELF_MANAGED
638+
and the backends are instance groups. The named port must be defined on each
639+
backend instance group. This parameter has no meaning if the backends are NEGs. API sets a
640+
default of "http" if not given.
641+
Must be omitted when the loadBalancingScheme is INTERNAL (Internal TCP/UDP Load Balancing).`,
642+
},
631643
"protocol": {
632644
Type: schema.TypeString,
633645
Computed: true,
@@ -904,6 +916,12 @@ func resourceComputeRegionBackendServiceCreate(d *schema.ResourceData, meta inte
904916
} else if v, ok := d.GetOkExists("outlier_detection"); !isEmptyValue(reflect.ValueOf(outlierDetectionProp)) && (ok || !reflect.DeepEqual(v, outlierDetectionProp)) {
905917
obj["outlierDetection"] = outlierDetectionProp
906918
}
919+
portNameProp, err := expandComputeRegionBackendServicePortName(d.Get("port_name"), d, config)
920+
if err != nil {
921+
return err
922+
} else if v, ok := d.GetOkExists("port_name"); !isEmptyValue(reflect.ValueOf(portNameProp)) && (ok || !reflect.DeepEqual(v, portNameProp)) {
923+
obj["portName"] = portNameProp
924+
}
907925
protocolProp, err := expandComputeRegionBackendServiceProtocol(d.Get("protocol"), d, config)
908926
if err != nil {
909927
return err
@@ -1068,6 +1086,9 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf
10681086
if err := d.Set("outlier_detection", flattenComputeRegionBackendServiceOutlierDetection(res["outlierDetection"], d, config)); err != nil {
10691087
return fmt.Errorf("Error reading RegionBackendService: %s", err)
10701088
}
1089+
if err := d.Set("port_name", flattenComputeRegionBackendServicePortName(res["portName"], d, config)); err != nil {
1090+
return fmt.Errorf("Error reading RegionBackendService: %s", err)
1091+
}
10711092
if err := d.Set("protocol", flattenComputeRegionBackendServiceProtocol(res["protocol"], d, config)); err != nil {
10721093
return fmt.Errorf("Error reading RegionBackendService: %s", err)
10731094
}
@@ -1180,6 +1201,12 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte
11801201
} else if v, ok := d.GetOkExists("outlier_detection"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, outlierDetectionProp)) {
11811202
obj["outlierDetection"] = outlierDetectionProp
11821203
}
1204+
portNameProp, err := expandComputeRegionBackendServicePortName(d.Get("port_name"), d, config)
1205+
if err != nil {
1206+
return err
1207+
} else if v, ok := d.GetOkExists("port_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, portNameProp)) {
1208+
obj["portName"] = portNameProp
1209+
}
11831210
protocolProp, err := expandComputeRegionBackendServiceProtocol(d.Get("protocol"), d, config)
11841211
if err != nil {
11851212
return err
@@ -2091,6 +2118,10 @@ func flattenComputeRegionBackendServiceOutlierDetectionSuccessRateStdevFactor(v
20912118
return v // let terraform core handle it otherwise
20922119
}
20932120

2121+
func flattenComputeRegionBackendServicePortName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
2122+
return v
2123+
}
2124+
20942125
func flattenComputeRegionBackendServiceProtocol(v interface{}, d *schema.ResourceData, config *Config) interface{} {
20952126
return v
20962127
}
@@ -2808,6 +2839,10 @@ func expandComputeRegionBackendServiceOutlierDetectionSuccessRateStdevFactor(v i
28082839
return v, nil
28092840
}
28102841

2842+
func expandComputeRegionBackendServicePortName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2843+
return v, nil
2844+
}
2845+
28112846
func expandComputeRegionBackendServiceProtocol(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
28122847
return v, nil
28132848
}

google-beta/resource_compute_region_backend_service_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ func testAccComputeRegionBackendService_ilbBasic(serviceName, checkName string)
240240
resource "google_compute_region_backend_service" "foobar" {
241241
name = "%s"
242242
health_checks = [google_compute_health_check.health_check.self_link]
243+
port_name = "http"
243244
protocol = "HTTP"
244245
load_balancing_scheme = "INTERNAL_MANAGED"
245246
locality_lb_policy = "RING_HASH"
@@ -274,6 +275,7 @@ func testAccComputeRegionBackendService_ilbUpdateBasic(serviceName, checkName st
274275
resource "google_compute_region_backend_service" "foobar" {
275276
name = "%s"
276277
health_checks = [google_compute_health_check.health_check.self_link]
278+
port_name = "https"
277279
protocol = "HTTP"
278280
load_balancing_scheme = "INTERNAL_MANAGED"
279281
locality_lb_policy = "RANDOM"
@@ -299,6 +301,7 @@ func testAccComputeRegionBackendService_ilbFull(serviceName, checkName string) s
299301
resource "google_compute_region_backend_service" "foobar" {
300302
name = "%s"
301303
health_checks = [google_compute_health_check.health_check.self_link]
304+
port_name = "http"
302305
protocol = "HTTP"
303306
load_balancing_scheme = "INTERNAL_MANAGED"
304307
locality_lb_policy = "MAGLEV"
@@ -333,6 +336,7 @@ func testAccComputeRegionBackendService_ilbUpdateFull(serviceName, igName, insta
333336
resource "google_compute_region_backend_service" "foobar" {
334337
name = "%s"
335338
health_checks = [google_compute_health_check.health_check.self_link]
339+
port_name = "https"
336340
protocol = "HTTP"
337341
load_balancing_scheme = "INTERNAL_MANAGED"
338342
locality_lb_policy = "MAGLEV"
@@ -392,6 +396,16 @@ resource "google_compute_region_backend_service" "foobar" {
392396
resource "google_compute_instance_group" "group" {
393397
name = "%s"
394398
instances = [google_compute_instance.ig_instance.self_link]
399+
400+
named_port {
401+
name = "http"
402+
port = "8080"
403+
}
404+
405+
named_port {
406+
name = "https"
407+
port = "8443"
408+
}
395409
}
396410
397411
data "google_compute_image" "my_image" {
@@ -429,6 +443,7 @@ resource "google_compute_region_backend_service" "foobar" {
429443
name = "%s"
430444
health_checks = [google_compute_health_check.zero.self_link]
431445
region = "us-central1"
446+
port_name = "http"
432447
}
433448
434449
resource "google_compute_health_check" "zero" {
@@ -449,6 +464,7 @@ resource "google_compute_region_backend_service" "foobar" {
449464
name = "%s"
450465
health_checks = [google_compute_health_check.one.self_link]
451466
region = "us-central1"
467+
port_name = "http"
452468
}
453469
454470
resource "google_compute_health_check" "zero" {
@@ -484,6 +500,7 @@ data "google_compute_image" "my_image" {
484500
resource "google_compute_region_backend_service" "lipsum" {
485501
name = "%s"
486502
description = "Hello World 1234"
503+
port_name = "http"
487504
protocol = "TCP"
488505
region = "us-central1"
489506
timeout_sec = %v
@@ -551,6 +568,7 @@ data "google_compute_image" "my_image" {
551568
resource "google_compute_region_backend_service" "lipsum" {
552569
name = "%s"
553570
description = "Hello World 1234"
571+
port_name = "http"
554572
protocol = "TCP"
555573
region = "us-central1"
556574
timeout_sec = %v
@@ -650,6 +668,7 @@ data "google_compute_image" "my_image" {
650668
resource "google_compute_region_backend_service" "lipsum" {
651669
name = "%s"
652670
description = "Hello World 1234"
671+
port_name = "http"
653672
protocol = "TCP"
654673
region = "us-central1"
655674
@@ -712,6 +731,7 @@ resource "google_compute_region_backend_service" "default" {
712731
}
713732
714733
region = "us-central1"
734+
port_name = "http"
715735
protocol = "HTTP"
716736
timeout_sec = 10
717737
@@ -779,6 +799,7 @@ resource "google_compute_region_backend_service" "default" {
779799
}
780800
781801
region = "us-central1"
802+
port_name = "http"
782803
protocol = "HTTP"
783804
timeout_sec = 10
784805
@@ -856,6 +877,7 @@ resource "google_compute_region_backend_service" "default" {
856877
}
857878
858879
region = "us-central1"
880+
port_name = "http"
859881
protocol = "HTTP"
860882
timeout_sec = 10
861883

website/docs/r/compute_region_backend_service.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ The following arguments are supported:
327327
This field is applicable only when the `load_balancing_scheme` is set
328328
to INTERNAL_MANAGED and the `protocol` is set to HTTP, HTTPS, or HTTP2. Structure is documented below.
329329

330+
* `port_name` -
331+
(Optional)
332+
A named port on a backend instance group representing the port for
333+
communication to the backend VMs in that group. Required when the
334+
loadBalancingScheme is EXTERNAL, INTERNAL_MANAGED, or INTERNAL_SELF_MANAGED
335+
and the backends are instance groups. The named port must be defined on each
336+
backend instance group. This parameter has no meaning if the backends are NEGs. API sets a
337+
default of "http" if not given.
338+
Must be omitted when the loadBalancingScheme is INTERNAL (Internal TCP/UDP Load Balancing).
339+
330340
* `protocol` -
331341
(Optional)
332342
The protocol this RegionBackendService uses to communicate with backends.

0 commit comments

Comments
 (0)