Skip to content

Commit

Permalink
Support proxy protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
itakouna committed Jul 11, 2023
1 parent 8d0608f commit 5b15d5c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions gridscale/datasource_gridscale_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func dataSourceGridscaleLoadBalancer() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"proxy_protocol": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions gridscale/datasource_gridscale_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestAccdataSourceGridscaleLoadBalancer_basic(t *testing.T) {
resource.TestCheckResourceAttr("data.gridscale_loadbalancer.foo", "forwarding_rule.0.listen_port", "80"),
resource.TestCheckResourceAttr("data.gridscale_loadbalancer.foo", "backend_server.#", "1"),
resource.TestCheckResourceAttr("data.gridscale_loadbalancer.foo", "backend_server.0.weight", "100"),
resource.TestCheckResourceAttr("data.gridscale_loadbalancer.foo", "backend_server.0.proxy_protocol", "v2"),
),
},
},
Expand Down Expand Up @@ -56,6 +57,7 @@ resource "gridscale_loadbalancer" "foo" {
backend_server {
weight = 100
host = gridscale_ipv4.server.ip
proxy_protocol = "v2"
}
forwarding_rule {
listen_port = 80
Expand Down
15 changes: 11 additions & 4 deletions gridscale/resource_gridscale_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func resourceGridscaleLoadBalancer() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"proxy_protocol": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -282,9 +286,11 @@ func expandLoadbalancerBackendServers(backendServers interface{}) []gsclient.Bac
tempBackendServers := []gsclient.BackendServer{}
for _, value := range backendServers.(*schema.Set).List() {
server := value.(map[string]interface{})
proxyProtocol := server["proxy_protocol"].(string)
backendServer := gsclient.BackendServer{
Weight: server["weight"].(int),
Host: server["host"].(string),
Weight: server["weight"].(int),
Host: server["host"].(string),
ProxyProtocol: &proxyProtocol,
}
tempBackendServers = append(tempBackendServers, backendServer)
}
Expand Down Expand Up @@ -333,8 +339,9 @@ func flattenLoadbalancerBackendServers(backendServers []gsclient.BackendServer)
if backendServers != nil {
for _, value := range backendServers {
backendServer := map[string]interface{}{
"weight": value.Weight,
"host": value.Host,
"weight": value.Weight,
"host": value.Host,
"proxy_protocol": value.ProxyProtocol,
}
tempBackendServers = append(tempBackendServers, backendServer)
}
Expand Down
7 changes: 6 additions & 1 deletion gridscale/resource_gridscale_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestAccResourceGridscaleLoadBalancerBasic(t *testing.T) {
"gridscale_loadbalancer.foo", "name", name),
resource.TestCheckResourceAttr(
"gridscale_loadbalancer.foo", "algorithm", "leastconn"),
resource.TestCheckResourceAttr(
"gridscale_loadbalancer.foo", "backend_server.0.proxy_protocol", "v2"),
),
},
{
Expand All @@ -38,7 +40,7 @@ func TestAccResourceGridscaleLoadBalancerBasic(t *testing.T) {
resource.TestCheckResourceAttr(
"gridscale_loadbalancer.foo", "name", "newname"),
resource.TestCheckResourceAttr(
"gridscale_loadbalancer.foo", "algorithm", "roundrobin"),
"gridscale_loadbalancer.foo", "backend_server.0.proxy_protocol", "v1"),
),
},
},
Expand Down Expand Up @@ -98,6 +100,8 @@ resource "gridscale_loadbalancer" "foo" {
backend_server {
weight = 100
host = gridscale_ipv4.server.ip
proxy_protocol = v2
}
forwarding_rule {
listen_port = 80
Expand Down Expand Up @@ -128,6 +132,7 @@ resource "gridscale_loadbalancer" "foo" {
backend_server {
weight = 100
host = gridscale_ipv4.server.ip
proxy_protocol = v1
}
forwarding_rule {
listen_port = 80
Expand Down

0 comments on commit 5b15d5c

Please sign in to comment.