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 for new load balancing monitor types #1371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1371.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_load_balancer_monitor: added support for smtp, icmp_ping, and udp_icmp monitors
```
74 changes: 74 additions & 0 deletions cloudflare/resource_cloudflare_load_balancer_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,45 @@ func TestAccCloudflareLoadBalancerMonitor_TcpFullySpecified(t *testing.T) {
})
}

func TestAccCloudflareLoadBalancerMonitor_PremiumTypes(t *testing.T) {
t.Parallel()
var loadBalancerMonitor cloudflare.LoadBalancerMonitor
rnd := generateRandomResourceName()
name := fmt.Sprintf("cloudflare_load_balancer_monitor.%s", rnd)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudflareLoadBalancerMonitorDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudflareLoadBalancerMonitorConfigUDPICMP(rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareLoadBalancerMonitorExists(name, &loadBalancerMonitor),
// check we can create one of the correct type
resource.TestCheckResourceAttr(name, "type", "udp_icmp"),
),
},
{
Config: testAccCheckCloudflareLoadBalancerMonitorConfigICMPPing(rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareLoadBalancerMonitorExists(name, &loadBalancerMonitor),
// check we can create one of the correct type
resource.TestCheckResourceAttr(name, "type", "icmp_ping"),
),
},
{
Config: testAccCheckCloudflareLoadBalancerMonitorConfigSMTP(rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareLoadBalancerMonitorExists(name, &loadBalancerMonitor),
// checking our overrides of default values worked
resource.TestCheckResourceAttr(name, "type", "smtp"),
),
},
},
})
}

func TestAccCloudflareLoadBalancerMonitor_NoRequired(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -331,6 +370,41 @@ resource "cloudflare_load_balancer_monitor" "test" {
}`
}

func testAccCheckCloudflareLoadBalancerMonitorConfigUDPICMP(resourceName string) string {
return fmt.Sprintf(`
resource "cloudflare_load_balancer_monitor" "%s" {
type = "udp_icmp"
timeout = 2
interval = 60
retries = 5
port = 8080
description = "test setup udp_icmp"
}`, resourceName)
}

func testAccCheckCloudflareLoadBalancerMonitorConfigICMPPing(resourceName string) string {
return fmt.Sprintf(`
resource "cloudflare_load_balancer_monitor" "%s" {
type = "icmp_ping"
timeout = 2
interval = 60
retries = 5
description = "test setup icmp_ping"
}`, resourceName)
}

func testAccCheckCloudflareLoadBalancerMonitorConfigSMTP(resourceName string) string {
return fmt.Sprintf(`
resource "cloudflare_load_balancer_monitor" "%s" {
type = "smtp"
timeout = 2
interval = 60
retries = 5
port = 8080
description = "test setup smtp"
}`, resourceName)
}

func testAccCheckCloudflareLoadBalancerMonitorConfigMissingRequired() string {
return `
resource "cloudflare_load_balancer_monitor" "test" {
Expand Down
2 changes: 1 addition & 1 deletion cloudflare/schema_cloudflare_load_balancer_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func resourceCloudflareLoadBalancerMonitorSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Optional: true,
Default: "http",
ValidateFunc: validation.StringInSlice([]string{"http", "https", "tcp"}, false),
ValidateFunc: validation.StringInSlice([]string{"http", "https", "tcp", "udp_icmp", "icmp_ping", "smtp"}, false),
},

"created_on": {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/load_balancer_monitor.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ The following arguments are supported:

* `expected_body` - (Optional) 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". Default: "".
* `expected_codes` - (Optional) The expected HTTP response code or code range of the health check. Eg `2xx`. Only valid and required if `type` is "http" or "https".
* `method` - (Optional) The method to use for the health check. Valid values are any valid HTTP verb if `type` is "http" or "https", or `connection_established` if `type` is "tcp". Default: "GET" if `type` is "http" or "https", or "connection_established" if `type` is "tcp" .
* `method` - (Optional) The method to use for the health check. Valid values are any valid HTTP verb if `type` is "http" or "https", or `connection_established` if `type` is "tcp". Default: "GET" if `type` is "http" or "https", "connection_established" if `type` is "tcp", and empty otherwise.
* `timeout` - (Optional) The timeout (in seconds) before marking the health check as failed. Default: 5.
* `path` - (Optional) The endpoint path to health check against. Default: "/". Only valid if `type` is "http" or "https".
* `interval` - (Optional) The interval between each health check. Shorter intervals may improve failover time, but will increase load on the origins as we check from multiple locations. Default: 60.
* `retries` - (Optional) The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately. Default: 2.
* `header` - (Optional) The HTTP request headers to send in the health check. It is recommended you set a Host header by default. The User-Agent header cannot be overridden. Fields documented below. Only valid if `type` is "http" or "https".
* `type` - (Optional) The protocol to use for the healthcheck. Currently supported protocols are 'HTTP', 'HTTPS' and 'TCP'. Default: "http".
* `type` - (Optional) The protocol to use for the healthcheck. Currently supported protocols are 'HTTP', 'HTTPS', 'TCP', 'UDP-ICMP', 'ICMP-PING', and 'SMTP'. Default: "http".
* `port` - The port number to use for the healthcheck, required when creating a TCP monitor. Valid values are in the range `0-65535`.
* `description` - (Optional) Free text description.
* `allow_insecure` - (Optional) Do not validate the certificate when monitor use HTTPS. Only valid if `type` is "http" or "https".
Expand Down