Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTP idle timeout & Project ID #897

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Support HTTP idle timeout & project_id
  • Loading branch information
StephenVarela committed Nov 21, 2022
commit 9e2565a2158267afe374d6ecb69641e3a7a313fe
21 changes: 21 additions & 0 deletions digitalocean/resource_digitalocean_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ func resourceDigitalOceanLoadBalancerV0() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"http_idle_timeout_seconds": {
Type: schema.TypeInt,
Optional: true,
Default: nil,
},

"project_id": {
Type: schema.TypeString,
Optional: true,
Default: "",
},
},
}
}
Expand Down Expand Up @@ -413,6 +425,7 @@ func buildLoadBalancerRequest(client *godo.Client, d *schema.ResourceData) (*god
EnableBackendKeepalive: d.Get("enable_backend_keepalive").(bool),
ForwardingRules: forwardingRules,
DisableLetsEncryptDNSRecords: godo.Bool(d.Get("disable_lets_encrypt_dns_records").(bool)),
ProjectID: d.Get("project_id").(string),
}
sizeUnit, ok := d.GetOk("size_unit")
if ok {
Expand All @@ -421,6 +434,12 @@ func buildLoadBalancerRequest(client *godo.Client, d *schema.ResourceData) (*god
opts.SizeSlug = d.Get("size").(string)
}

idleTimeout, ok := d.GetOk("http_idle_timeout_seconds")
if ok {
t := uint64(idleTimeout.(int))
opts.HTTPIdleTimeoutSeconds = &t
}

if v, ok := d.GetOk("droplet_tag"); ok {
opts.Tag = v.(string)
} else if v, ok := d.GetOk("droplet_ids"); ok {
Expand Down Expand Up @@ -505,6 +524,8 @@ func resourceDigitalOceanLoadbalancerRead(ctx context.Context, d *schema.Resourc
d.Set("enable_backend_keepalive", loadbalancer.EnableBackendKeepalive)
d.Set("droplet_tag", loadbalancer.Tag)
d.Set("vpc_uuid", loadbalancer.VPCUUID)
d.Set("http_idle_timeout_seconds", loadbalancer.HTTPIdleTimeoutSeconds)

if loadbalancer.SizeUnit > 0 {
d.Set("size_unit", loadbalancer.SizeUnit)
} else {
Expand Down
16 changes: 16 additions & 0 deletions digitalocean/resource_digitalocean_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func TestAccDigitalOceanLoadbalancer_Basic(t *testing.T) {
"digitalocean_loadbalancer.foobar", "enable_backend_keepalive", "true"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "disable_lets_encrypt_dns_records", "false"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "http_idle_timeout_seconds", "90"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "project_id", "my-project-uuid"),
),
},
},
Expand Down Expand Up @@ -152,6 +156,10 @@ func TestAccDigitalOceanLoadbalancer_Updated(t *testing.T) {
"digitalocean_loadbalancer.foobar", "enable_backend_keepalive", "true"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "disable_lets_encrypt_dns_records", "false"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "http_idle_timeout_seconds", "90"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "project_id", "my-project-uuid"),
),
},
{
Expand Down Expand Up @@ -191,6 +199,10 @@ func TestAccDigitalOceanLoadbalancer_Updated(t *testing.T) {
"digitalocean_loadbalancer.foobar", "enable_backend_keepalive", "false"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "disable_lets_encrypt_dns_records", "true"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "http_idle_timeout_seconds", "120"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "project_id", "my-project-uuid"),
),
},
},
Expand Down Expand Up @@ -728,6 +740,8 @@ resource "digitalocean_loadbalancer" "foobar" {

enable_proxy_protocol = true
enable_backend_keepalive = true
http_idle_timeout_seconds = 90
project_id = "my-project-uuid"

droplet_ids = [digitalocean_droplet.foobar.id]
}`, rInt, rInt)
Expand Down Expand Up @@ -769,6 +783,8 @@ resource "digitalocean_loadbalancer" "foobar" {
enable_proxy_protocol = false
enable_backend_keepalive = false
disable_lets_encrypt_dns_records = true
http_idle_timeout_seconds = 120
project_id = "my-project-uuid"

droplet_ids = [digitalocean_droplet.foobar.id, digitalocean_droplet.foo.id]
}`, rInt, rInt, rInt)
Expand Down
1 change: 1 addition & 0 deletions docs/resources/loadbalancer.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ the backend service. Default value is `false`.
* `type` - (Required) An attribute indicating how and if requests from a client will be persistently served by the same backend Droplet. The possible values are `cookies` or `none`. If not specified, the default value is `none`.
* `cookie_name` - (Optional) The name to be used for the cookie sent to the client. This attribute is required when using `cookies` for the sticky sessions type.
* `cookie_ttl_seconds` - (Optional) The number of seconds until the cookie set by the Load Balancer expires. This attribute is required when using `cookies` for the sticky sessions type.
* `http_idle_timeout_seconds` - (Optional) The http idle timeout configuration in seconds. if not specified, this defaults to 60 seconds.


`healthcheck` supports the following:
Expand Down