Skip to content

Commit c4eddd8

Browse files
committed
Support Proxy Protocol for TCP Listeners
1 parent f5f20f4 commit c4eddd8

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## 3.62.0 (Unreleased)
2+
3+
### Added
4+
- Support Proxy Protocol for `oci_load_balancer_listener`
5+
26
## 3.61.0 (February 05, 2020)
37

48
### Added

examples/load_balancer/lb_full/lb_full.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,20 @@ resource "oci_load_balancer_listener" "lb-listener2" {
314314
}
315315
}
316316

317+
resource "oci_load_balancer_listener" "lb-listener3" {
318+
load_balancer_id = "${oci_load_balancer.lb1.id}"
319+
name = "tcp"
320+
default_backend_set_name = "${oci_load_balancer_backend_set.lb-bes1.name}"
321+
port = 80
322+
protocol = "TCP"
323+
rule_set_names = ["${oci_load_balancer_rule_set.test_rule_set.name}"]
324+
325+
connection_configuration {
326+
idle_timeout_in_seconds = "2"
327+
backend_tcp_proxy_protocol_version = "1"
328+
}
329+
}
330+
317331
resource "oci_load_balancer_backend" "lb-be1" {
318332
load_balancer_id = "${oci_load_balancer.lb1.id}"
319333
backendset_name = "${oci_load_balancer_backend_set.lb-bes1.name}"

oci/load_balancer_listener_resource.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ func LoadBalancerListenerResource() *schema.Resource {
6969
},
7070

7171
// Optional
72+
"backend_tcp_proxy_protocol_version": {
73+
Type: schema.TypeInt,
74+
Optional: true,
75+
},
7276

7377
// Computed
7478
},
@@ -577,6 +581,15 @@ func parseListenerCompositeId(compositeId string) (listenerName string, loadBala
577581
func (s *LoadBalancerListenerResourceCrud) mapToConnectionConfiguration(fieldKeyFormat string) (oci_load_balancer.ConnectionConfiguration, error) {
578582
result := oci_load_balancer.ConnectionConfiguration{}
579583

584+
if backendTcpProxyProtocolVersion, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "backend_tcp_proxy_protocol_version")); ok {
585+
tmp := backendTcpProxyProtocolVersion.(int)
586+
// Terraform v11 will auto assign nil value to 0 which is invalid value
587+
// this check will remove backend_tcp_proxy_protocol_version in the request
588+
if tmp != 0 {
589+
result.BackendTcpProxyProtocolVersion = &tmp
590+
}
591+
}
592+
580593
if idleTimeoutInSeconds, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "idle_timeout_in_seconds")); ok {
581594
tmp := idleTimeoutInSeconds.(string)
582595
tmpInt64, err := strconv.ParseInt(tmp, 10, 64)
@@ -592,6 +605,10 @@ func (s *LoadBalancerListenerResourceCrud) mapToConnectionConfiguration(fieldKey
592605
func ConnectionConfigurationToMap(obj *oci_load_balancer.ConnectionConfiguration) map[string]interface{} {
593606
result := map[string]interface{}{}
594607

608+
if obj.BackendTcpProxyProtocolVersion != nil {
609+
result["backend_tcp_proxy_protocol_version"] = int(*obj.BackendTcpProxyProtocolVersion)
610+
}
611+
595612
if obj.IdleTimeout != nil {
596613
result["idle_timeout_in_seconds"] = strconv.FormatInt(*obj.IdleTimeout, 10)
597614
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
3+
package oci
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform/helper/resource"
10+
"github.com/hashicorp/terraform/terraform"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
13+
)
14+
15+
var (
16+
ListenerTcpRequiredOnlyResource = ListenerResourceDependencies +
17+
generateResourceFromRepresentationMap("oci_load_balancer_listener", "test_listener_tcp", Required, Create, listenerTcpRepresentation)
18+
listenerTcpRepresentation = map[string]interface{}{
19+
"default_backend_set_name": Representation{repType: Required, create: `${oci_load_balancer_backend_set.test_backend_set.name}`},
20+
"load_balancer_id": Representation{repType: Required, create: `${oci_load_balancer_load_balancer.test_load_balancer.id}`},
21+
"name": Representation{repType: Required, create: `mylistener`},
22+
"port": Representation{repType: Required, create: `10`, update: `11`},
23+
"protocol": Representation{repType: Required, create: `TCP`},
24+
"connection_configuration": RepresentationGroup{Optional, listenerTcpConnectionConfigurationRepresentation},
25+
"rule_set_names": Representation{repType: Optional, create: []string{`${oci_load_balancer_rule_set.test_rule_set.name}`}},
26+
}
27+
listenerTcpConnectionConfigurationRepresentation = map[string]interface{}{
28+
"idle_timeout_in_seconds": Representation{repType: Required, create: `10`, update: `11`},
29+
"backend_tcp_proxy_protocol_version": Representation{repType: Optional, create: `1`, update: `2`},
30+
}
31+
)
32+
33+
func TestLoadBalancerListenerTcpResource_basic(t *testing.T) {
34+
httpreplay.SetScenario("TestLoadBalancerListenerTcpResource_basic")
35+
defer httpreplay.SaveScenario()
36+
37+
provider := testAccProvider
38+
config := testProviderConfig()
39+
40+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
41+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
42+
43+
resourceName := "oci_load_balancer_listener.test_listener_tcp"
44+
45+
resource.Test(t, resource.TestCase{
46+
PreCheck: func() { testAccPreCheck(t) },
47+
Providers: map[string]terraform.ResourceProvider{
48+
"oci": provider,
49+
},
50+
CheckDestroy: testAccCheckLoadBalancerListenerDestroy,
51+
Steps: []resource.TestStep{
52+
// verify create with TCP optional
53+
{
54+
Config: config + compartmentIdVariableStr + ListenerResourceDependencies +
55+
generateResourceFromRepresentationMap("oci_load_balancer_listener", "test_listener_tcp", Optional, Create, listenerTcpRepresentation),
56+
Check: resource.ComposeAggregateTestCheckFunc(
57+
resource.TestCheckResourceAttr(resourceName, "connection_configuration.#", "1"),
58+
resource.TestCheckResourceAttr(resourceName, "connection_configuration.0.backend_tcp_proxy_protocol_version", "1"),
59+
resource.TestCheckResourceAttr(resourceName, "connection_configuration.0.idle_timeout_in_seconds", "10"),
60+
resource.TestCheckResourceAttrSet(resourceName, "load_balancer_id"),
61+
resource.TestCheckResourceAttr(resourceName, "name", "mylistener"),
62+
resource.TestCheckResourceAttr(resourceName, "port", "10"),
63+
resource.TestCheckResourceAttr(resourceName, "protocol", "TCP"),
64+
resource.TestCheckResourceAttr(resourceName, "rule_set_names.#", "1"),
65+
),
66+
},
67+
68+
// verify update with TCP optional
69+
{
70+
Config: config + compartmentIdVariableStr + ListenerResourceDependencies +
71+
generateResourceFromRepresentationMap("oci_load_balancer_listener", "test_listener_tcp", Optional, Update, listenerTcpRepresentation),
72+
Check: resource.ComposeAggregateTestCheckFunc(
73+
resource.TestCheckResourceAttr(resourceName, "connection_configuration.#", "1"),
74+
resource.TestCheckResourceAttr(resourceName, "connection_configuration.0.backend_tcp_proxy_protocol_version", "2"),
75+
resource.TestCheckResourceAttr(resourceName, "connection_configuration.0.idle_timeout_in_seconds", "11"),
76+
resource.TestCheckResourceAttrSet(resourceName, "load_balancer_id"),
77+
resource.TestCheckResourceAttr(resourceName, "name", "mylistener"),
78+
resource.TestCheckResourceAttr(resourceName, "port", "11"),
79+
resource.TestCheckResourceAttr(resourceName, "protocol", "TCP"),
80+
resource.TestCheckResourceAttr(resourceName, "rule_set_names.#", "1"),
81+
),
82+
},
83+
},
84+
})
85+
}

website/docs/r/load_balancer_listener.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ resource "oci_load_balancer_listener" "test_listener" {
2727
connection_configuration {
2828
#Required
2929
idle_timeout_in_seconds = "${var.listener_connection_configuration_idle_timeout_in_seconds}"
30+
31+
#Optional
32+
backend_tcp_proxy_protocol_version = "${var.listener_connection_configuration_backend_tcp_proxy_protocol_version}"
3033
}
3134
hostname_names = ["${oci_load_balancer_hostname.test_hostname.name}"]
3235
path_route_set_name = "${oci_load_balancer_path_route_set.test_path_route_set.name}"
@@ -47,6 +50,7 @@ resource "oci_load_balancer_listener" "test_listener" {
4750
The following arguments are supported:
4851

4952
* `connection_configuration` - (Optional) (Updatable)
53+
* `backend_tcp_proxy_protocol_version` - (Required when `protocol` = `TCP`) (Updatable) The backend TCP Proxy Protocol version. Example: `1`
5054
* `idle_timeout_in_seconds` - (Required) (Updatable) The maximum idle time, in seconds, allowed between two successive receive or two successive send operations between the client and backend servers. A send operation does not reset the timer for receive operations. A receive operation does not reset the timer for send operations.
5155

5256
For more information, see [Connection Configuration](https://docs.cloud.oracle.com/iaas/Content/Balance/Reference/connectionreuse.htm#ConnectionConfiguration).

0 commit comments

Comments
 (0)