Skip to content

Commit 782cee3

Browse files
authored
feat(lb): replace send_proxy_v2 by proxy_protocol (#546)
1 parent ab01135 commit 782cee3

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

scaleway/helpers_lb.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scaleway
22

33
import (
4+
"strings"
45
"time"
56

67
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@@ -236,3 +237,11 @@ func expandLbCustomCertificate(raw interface{}) *lb.CreateCertificateRequestCust
236237
}
237238
return config
238239
}
240+
241+
func expandLbProxyProtocol(raw interface{}) lb.ProxyProtocol {
242+
return lb.ProxyProtocol("proxy_protocol_" + raw.(string))
243+
}
244+
245+
func flattenLbProxyProtocol(pp lb.ProxyProtocol) interface{} {
246+
return strings.TrimPrefix(pp.String(), "proxy_protocol_")
247+
}

scaleway/resource_lb_backend_beta.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,21 @@ func resourceScalewayLbBackendBeta() *schema.Resource {
8383
Description: "Enables PROXY protocol version 2",
8484
Optional: true,
8585
Default: false,
86+
Deprecated: "Please use proxy_protocol instead",
87+
},
88+
"proxy_protocol": {
89+
Type: schema.TypeString,
90+
Description: "Type of PROXY protocol to enable",
91+
Optional: true,
92+
Default: lb.ProxyProtocolProxyProtocolNone,
93+
ValidateFunc: validation.StringInSlice([]string{
94+
flattenLbProxyProtocol(lb.ProxyProtocolProxyProtocolNone).(string),
95+
flattenLbProxyProtocol(lb.ProxyProtocolProxyProtocolV1).(string),
96+
flattenLbProxyProtocol(lb.ProxyProtocolProxyProtocolV2).(string),
97+
flattenLbProxyProtocol(lb.ProxyProtocolProxyProtocolV2Ssl).(string),
98+
flattenLbProxyProtocol(lb.ProxyProtocolProxyProtocolV2SslCn).(string),
99+
}, false),
86100
},
87-
88101
// Timeouts
89102
"timeout_server": {
90103
Type: schema.TypeString,
@@ -248,6 +261,7 @@ func resourceScalewayLbBackendBetaCreate(d *schema.ResourceData, m interface{})
248261
},
249262
ServerIP: expandStrings(d.Get("server_ips")),
250263
SendProxyV2: d.Get("send_proxy_v2").(bool),
264+
ProxyProtocol: expandLbProxyProtocol(d.Get("proxy_protocol")),
251265
TimeoutServer: expandDuration(d.Get("timeout_server")),
252266
TimeoutConnect: expandDuration(d.Get("timeout_connect")),
253267
TimeoutTunnel: expandDuration(d.Get("timeout_tunnel")),
@@ -292,6 +306,7 @@ func resourceScalewayLbBackendBetaRead(d *schema.ResourceData, m interface{}) er
292306
_ = d.Set("sticky_sessions_cookie_name", res.StickySessionsCookieName)
293307
_ = d.Set("server_ips", res.Pool)
294308
_ = d.Set("send_proxy_v2", res.SendProxyV2)
309+
_ = d.Set("proxy_protocol", flattenLbProxyProtocol(res.ProxyProtocol))
295310
_ = d.Set("timeout_server", flattenDuration(res.TimeoutServer))
296311
_ = d.Set("timeout_connect", flattenDuration(res.TimeoutConnect))
297312
_ = d.Set("timeout_tunnel", flattenDuration(res.TimeoutTunnel))
@@ -323,6 +338,7 @@ func resourceScalewayLbBackendBetaUpdate(d *schema.ResourceData, m interface{})
323338
StickySessions: expandLbStickySessionsType(d.Get("sticky_sessions")),
324339
StickySessionsCookieName: d.Get("sticky_sessions_cookie_name").(string),
325340
SendProxyV2: d.Get("send_proxy_v2").(bool),
341+
ProxyProtocol: expandLbProxyProtocol(d.Get("proxy_protocol")),
326342
TimeoutServer: expandDuration(d.Get("timeout_server")),
327343
TimeoutConnect: expandDuration(d.Get("timeout_connect")),
328344
TimeoutTunnel: expandDuration(d.Get("timeout_tunnel")),

scaleway/resource_lb_backend_beta_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestAccScalewayLbBackendBeta(t *testing.T) {
3939
testAccCheckScalewayLbBackendBetaExists("scaleway_lb_backend_beta.bkd01"),
4040
resource.TestCheckResourceAttr("scaleway_lb_backend_beta.bkd01", "forward_port_algorithm", "roundrobin"),
4141
resource.TestCheckResourceAttr("scaleway_lb_backend_beta.bkd01", "sticky_sessions", "none"),
42-
resource.TestCheckResourceAttr("scaleway_lb_backend_beta.bkd01", "send_proxy_v2", "false"),
42+
resource.TestCheckResourceAttr("scaleway_lb_backend_beta.bkd01", "proxy_protocol", "none"),
4343
resource.TestCheckResourceAttr("scaleway_lb_backend_beta.bkd01", "timeout_server", ""),
4444
resource.TestCheckResourceAttr("scaleway_lb_backend_beta.bkd01", "on_marked_down_action", "none"),
4545
resource.TestCheckResourceAttr("scaleway_lb_backend_beta.bkd01", "health_check_timeout", "30s"),
@@ -70,7 +70,7 @@ func TestAccScalewayLbBackendBeta(t *testing.T) {
7070
sticky_sessions = "cookie"
7171
sticky_sessions_cookie_name = "session-id"
7272
server_ips = [ scaleway_instance_ip.ip02.address ]
73-
send_proxy_v2 = true
73+
proxy_protocol = "none"
7474
timeout_server = "1s"
7575
timeout_connect = "2.5s"
7676
timeout_tunnel = "3s"

website/docs/r/lb_backend_beta.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ The following arguments are supported:
5454
- `sticky_sessions` - (Default: `none`) Load balancing algorithm. Possible values are: `none`, `cookie` and `table`.
5555
- `sticky_sessions_cookie_name` - (Optional) Cookie name for for sticky sessions. Only applicable when sticky_sessions is set to `cookie`.
5656
- `server_ips` - (Optional) List of backend server IP addresses. Addresses can be either IPv4 or IPv6.
57-
- `send_proxy_v2` - (Default: `false`) Enables PROXY protocol version 2.
57+
- `send_proxy_v2` - DEPRECATED please use `proxy_protocol` instead - (Default: `false`) Enables PROXY protocol version 2.
58+
- `proxy_protocol` - (Default: `none`) Choose the type of PROXY protocol to enable (`none`, `v1`, `v2`, `v2_ssl`, `v2_ssl_cn`)
5859
- `timeout_server` - (Optional) Maximum server connection inactivity time. (e.g.: `1s`)
5960
- `timeout_connect` - (Optional) Maximum initial server connection establishment time. (e.g.: `1s`)
6061
- `timeout_tunnel` - (Optional) Maximum tunnel inactivity time. (e.g.: `1s`)

0 commit comments

Comments
 (0)