Skip to content

Commit

Permalink
Add connection limit for listener (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
lapson97 authored Feb 5, 2024
1 parent 89d7c9f commit dd2fec6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/data-sources/lblistener.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ output "view" {

### Optional

- `connection_limit` (Number)
- `loadbalancer_id` (String)
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
- `region_name` (String)
- `timeout_client_data` (Number)
- `timeout_member_connect` (Number)
- `timeout_member_data` (Number)

### Read-Only

Expand Down
4 changes: 4 additions & 0 deletions docs/resources/lblistener.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ resource "gcore_lblistener" "listener" {

### Optional

- `connection_limit` (Number)
- `insert_x_forwarded` (Boolean) Insert *-forwarded headers
- `last_updated` (String)
- `project_id` (Number)
Expand All @@ -54,6 +55,9 @@ resource "gcore_lblistener" "listener" {
- `region_name` (String)
- `secret_id` (String)
- `sni_secret_id` (List of String)
- `timeout_client_data` (Number)
- `timeout_member_connect` (Number)
- `timeout_member_data` (Number)
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-Only
Expand Down
20 changes: 20 additions & 0 deletions gcore/data_source_gcore_lblistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ func dataSourceLBListener() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"timeout_client_data": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"timeout_member_connect": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"timeout_member_data": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"connection_limit": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -128,6 +144,10 @@ func dataSourceLBListenerRead(ctx context.Context, d *schema.ResourceData, m int
d.Set("loadbalancer_id", lbID)
d.Set("project_id", d.Get("project_id").(int))
d.Set("region_id", d.Get("region_id").(int))
d.Set("timeout_client_data", lb.TimeoutClientData)
d.Set("timeout_member_connect", lb.TimeoutMemberConnect)
d.Set("timeout_member_data", lb.TimeoutMemberData)
d.Set("connection_limit", lb.ConnectionLimit)

log.Println("[DEBUG] Finish LBListener reading")
return diags
Expand Down
58 changes: 57 additions & 1 deletion gcore/resource_gcore_lblistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ func resourceLbListener() *schema.Resource {
Optional: true,
Computed: true,
},
"timeout_client_data": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"timeout_member_connect": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"timeout_member_data": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"connection_limit": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
},
}
}
Expand All @@ -169,6 +185,23 @@ func resourceLBListenerCreate(ctx context.Context, d *schema.ResourceData, m int
InsertXForwarded: d.Get("insert_x_forwarded").(bool),
SecretID: d.Get("secret_id").(string),
}
if tcd, ok := d.GetOkExists("timeout_client_data"); ok {
timeoutClientData := tcd.(int)
opts.TimeoutClientData = &timeoutClientData
}
if tmc, ok := d.GetOkExists("timeout_member_connect"); ok {
timeoutMemberConnect := tmc.(int)
opts.TimeoutMemberConnect = &timeoutMemberConnect
}
if tmd, ok := d.GetOkExists("timeout_member_data"); ok {
timeoutMemberConnect := tmd.(int)
opts.TimeoutMemberData = &timeoutMemberConnect
}
if cl, ok := d.GetOkExists("connection_limit"); ok {
connectionLimit := cl.(int)
opts.ConnectionLimit = &connectionLimit
}

sniSecretIDRaw := d.Get("sni_secret_id").([]interface{})
if len(sniSecretIDRaw) != 0 {
sniSecretID := make([]string, len(sniSecretIDRaw))
Expand Down Expand Up @@ -243,7 +276,7 @@ func resourceLBListenerUpdate(ctx context.Context, d *schema.ResourceData, m int
config := m.(*Config)
provider := config.Provider

client, err := CreateClient(provider, d, LBListenersPoint, versionPointV1)
client, err := CreateClient(provider, d, LBListenersPoint, versionPointV2)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -269,6 +302,29 @@ func resourceLBListenerUpdate(ctx context.Context, d *schema.ResourceData, m int
opts.SNISecretID = sniSecretID
changed = true
}
if d.HasChange("timeout_client_data") {
timeoutClientData := d.Get("timeout_client_data").(int)
opts.TimeoutClientData = &timeoutClientData
changed = true
}

if d.HasChange("timeout_member_connect") {
timeoutMemberConnect := d.Get("timeout_member_connect").(int)
opts.TimeoutMemberConnect = &timeoutMemberConnect
changed = true
}

if d.HasChange("timeout_member_data") {
timeoutMemberData := d.Get("timeout_member_data").(int)
opts.TimeoutMemberData = &timeoutMemberData
changed = true
}

if d.HasChange("connection_limit") {
connectionLimit := d.Get("connection_limit").(int)
opts.ConnectionLimit = &connectionLimit
changed = true
}

if changed {
_, err = listeners.Update(client, d.Id(), opts).Extract()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/G-Core/gcore-dns-sdk-go v0.2.7-0.20230801110428-99ef24b50d4d
github.com/G-Core/gcore-storage-sdk-go v0.1.34
github.com/G-Core/gcorelabscdn-go v1.0.3
github.com/G-Core/gcorelabscloud-go v0.6.28
github.com/G-Core/gcorelabscloud-go v0.6.30
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
github.com/mitchellh/mapstructure v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/G-Core/gcorelabscdn-go v1.0.1 h1:BsGnLIiH7nhvSwDLgnsaXIPIJZG6hpTsqeYP
github.com/G-Core/gcorelabscdn-go v1.0.1/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.3 h1:fBIhDNLqfKVQV7ycqhgNeyg4Pzn5LIl5yah556lAlj4=
github.com/G-Core/gcorelabscdn-go v1.0.3/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscloud-go v0.6.28 h1:o6rdeRNUr/k8ggJuMU/Fm7ZkO2k01TSdtXsjQtJqJZQ=
github.com/G-Core/gcorelabscloud-go v0.6.28/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/G-Core/gcorelabscloud-go v0.6.30 h1:v1fi5f5Tcr8FpsoP60j6beV0kcv84+mVH4vQopPu2oc=
github.com/G-Core/gcorelabscloud-go v0.6.30/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
Expand Down

0 comments on commit dd2fec6

Please sign in to comment.