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

Add Consecutive_up and Consecutive_down for load_balancer_monitor resource #2723

Merged
merged 9 commits into from
Sep 6, 2023
3 changes: 3 additions & 0 deletions .changelog/2723.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_load_balancer_monitor: add support for `consecutive_up` and `consecutive_down`
```
2 changes: 2 additions & 0 deletions docs/resources/load_balancer_monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ resource "cloudflare_load_balancer_monitor" "example" {
### Optional

- `allow_insecure` (Boolean) Do not validate the certificate when monitor use HTTPS. Only valid if `type` is "http" or "https".
- `consecutive_down` (Number) To be marked unhealthy the monitored origin must fail this healthcheck N consecutive times. Defaults to `0`.
- `consecutive_up` (Number) To be marked healthy the monitored origin must pass this healthcheck N consecutive times. Defaults to `0`.
- `description` (String) Free text description.
- `expected_body` (String) A case-insensitive sub-string to look for in the response body. If this string is not found, the origin will be marked as unhealthy. Only valid if `type` is "http" or "https".
- `expected_codes` (String) The expected HTTP response code or code range of the health check. Eg `2xx`. Only valid and required if `type` is "http" or "https".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ func resourceCloudflareLoadBalancerPoolMonitorCreate(ctx context.Context, d *sch
client := meta.(*cloudflare.API)

loadBalancerMonitor := cloudflare.LoadBalancerMonitor{
Timeout: d.Get("timeout").(int),
Type: d.Get("type").(string),
Interval: d.Get("interval").(int),
Retries: d.Get("retries").(int),
Timeout: d.Get("timeout").(int),
Type: d.Get("type").(string),
Interval: d.Get("interval").(int),
Retries: d.Get("retries").(int),
ConsecutiveUp: d.Get("consecutive_up").(int),
ConsecutiveDown: d.Get("consecutive_down").(int),
}

if description, ok := d.GetOk("description"); ok {
Expand Down Expand Up @@ -124,11 +126,13 @@ func resourceCloudflareLoadBalancerPoolMonitorUpdate(ctx context.Context, d *sch
client := meta.(*cloudflare.API)

loadBalancerMonitor := cloudflare.LoadBalancerMonitor{
ID: d.Id(),
Timeout: d.Get("timeout").(int),
Type: d.Get("type").(string),
Interval: d.Get("interval").(int),
Retries: d.Get("retries").(int),
ID: d.Id(),
Timeout: d.Get("timeout").(int),
Type: d.Get("type").(string),
Interval: d.Get("interval").(int),
Retries: d.Get("retries").(int),
ConsecutiveUp: d.Get("consecutive_up").(int),
ConsecutiveDown: d.Get("consecutive_down").(int),
}

if description, ok := d.GetOk("description"); ok {
Expand Down Expand Up @@ -246,6 +250,8 @@ func resourceCloudflareLoadBalancerPoolMonitorRead(ctx context.Context, d *schem

d.Set("description", loadBalancerMonitor.Description)
d.Set("interval", loadBalancerMonitor.Interval)
d.Set("consecutive_up", loadBalancerMonitor.ConsecutiveUp)
d.Set("consecutive_down", loadBalancerMonitor.ConsecutiveDown)
d.Set("method", loadBalancerMonitor.Method)
d.Set("port", int(loadBalancerMonitor.Port))
d.Set("retries", loadBalancerMonitor.Retries)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func TestAccCloudflareLoadBalancerMonitor_FullySpecified(t *testing.T) {
resource.TestCheckResourceAttr(name, "path", "/custom"),
resource.TestCheckResourceAttr(name, "header.#", "1"),
resource.TestCheckResourceAttr(name, "retries", "5"),
resource.TestCheckResourceAttr(name, "consecutive_up", "2"),
resource.TestCheckResourceAttr(name, "consecutive_down", "2"),
resource.TestCheckResourceAttr(name, "port", "8080"),
resource.TestCheckResourceAttr(name, "expected_body", "dead"),
resource.TestCheckResourceAttr(name, "probe_zone", zoneName),
Expand Down Expand Up @@ -424,6 +426,8 @@ resource "cloudflare_load_balancer_monitor" "%[3]s" {
path = "/custom"
interval = 60
retries = 5
consecutive_up = 2
consecutive_down = 2
port = 8080
description = "this is a very weird load balancer"
probe_zone = "%[1]s"
Expand Down
14 changes: 14 additions & 0 deletions internal/sdkv2provider/schema_cloudflare_load_balancer_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ func resourceCloudflareLoadBalancerMonitorSchema() map[string]*schema.Schema {
Description: "Do not validate the certificate when monitor use HTTPS. Only valid if `type` is \"http\" or \"https\"",
},

"consecutive_down": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "To be marked unhealthy the monitored origin must fail this healthcheck N consecutive times.",
},

"consecutive_up": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "To be marked healthy the monitored origin must pass this healthcheck N consecutive times.",
},

"expected_body": {
Type: schema.TypeString,
Optional: true,
Expand Down