From 94c63419e2142acf91d0e28c64676f47360dfcab Mon Sep 17 00:00:00 2001 From: ShiChangkuo Date: Fri, 19 Feb 2021 12:13:04 +0800 Subject: [PATCH] update docs for lb listener and pool --- docs/resources/lb_listener.md | 2 +- docs/resources/lb_pool.md | 7 +++- .../resource_huaweicloud_lb_listener.go | 2 +- huaweicloud/resource_huaweicloud_lb_pool.go | 41 ++++++------------- 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/docs/resources/lb_listener.md b/docs/resources/lb_listener.md index 73d52d08b8..a0b32dbc30 100644 --- a/docs/resources/lb_listener.md +++ b/docs/resources/lb_listener.md @@ -29,7 +29,7 @@ The following arguments are supported: If omitted, the provider-level region will be used. Changing this creates a new listener. -* `protocol` - (Required, String, ForceNew) The protocol can either be TCP, HTTP, HTTPS or TERMINATED_HTTPS. +* `protocol` - (Required, String, ForceNew) The protocol can either be TCP, UDP, HTTP or TERMINATED_HTTPS. Changing this creates a new listener. * `protocol_port` - (Required, Int, ForceNew) The port on which to listen for client traffic. diff --git a/docs/resources/lb_pool.md b/docs/resources/lb_pool.md index 9b667f38c1..8f2a5c15a7 100644 --- a/docs/resources/lb_pool.md +++ b/docs/resources/lb_pool.md @@ -38,7 +38,12 @@ The following arguments are supported: * `description` - (Optional, String) Human-readable description for the pool. -* `protocol` - (Required, String, ForceNew) The protocol - can either be TCP, HTTP or HTTPS. +* `protocol` - (Required, String, ForceNew) The protocol - can either be TCP, UDP or HTTP. + + - When the protocol used by the listener is UDP, the protocol of the backend pool must be UDP. + - When the protocol used by the listener is TCP, the protocol of the backend pool must be TCP. + - When the protocol used by the listener is HTTP or TERMINATED_HTTPS, the protocol of the backend pool must be HTTP. + Changing this creates a new pool. * `loadbalancer_id` - (Optional, String, ForceNew) The load balancer on which to provision this diff --git a/huaweicloud/resource_huaweicloud_lb_listener.go b/huaweicloud/resource_huaweicloud_lb_listener.go index 1f1b0acb8e..84ad846dc7 100644 --- a/huaweicloud/resource_huaweicloud_lb_listener.go +++ b/huaweicloud/resource_huaweicloud_lb_listener.go @@ -39,7 +39,7 @@ func ResourceListenerV2() *schema.Resource { Required: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - "TCP", "UDP", "HTTP", "HTTPS", "TERMINATED_HTTPS", + "TCP", "UDP", "HTTP", "TERMINATED_HTTPS", }, false), }, diff --git a/huaweicloud/resource_huaweicloud_lb_pool.go b/huaweicloud/resource_huaweicloud_lb_pool.go index da3d89cfef..9cfe14d110 100644 --- a/huaweicloud/resource_huaweicloud_lb_pool.go +++ b/huaweicloud/resource_huaweicloud_lb_pool.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/huaweicloud/golangsdk/openstack/networking/v2/extensions/lbaas_v2/pools" ) @@ -53,14 +54,9 @@ func ResourcePoolV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { - value := v.(string) - if value != "TCP" && value != "HTTP" && value != "HTTPS" { - errors = append(errors, fmt.Errorf( - "Only 'TCP', 'HTTP', and 'HTTPS' are supported values for 'protocol'")) - } - return - }, + ValidateFunc: validation.StringInSlice([]string{ + "TCP", "UDP", "HTTP", + }, false), }, // One of loadbalancer_id or listener_id must be provided @@ -80,14 +76,9 @@ func ResourcePoolV2() *schema.Resource { "lb_method": { Type: schema.TypeString, Required: true, - ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { - value := v.(string) - if value != "ROUND_ROBIN" && value != "LEAST_CONNECTIONS" && value != "SOURCE_IP" { - errors = append(errors, fmt.Errorf( - "Only 'ROUND_ROBIN', 'LEAST_CONNECTIONS', and 'SOURCE_IP' are supported values for 'lb_method'")) - } - return - }, + ValidateFunc: validation.StringInSlice([]string{ + "ROUND_ROBIN", "LEAST_CONNECTIONS", "SOURCE_IP", + }, false), }, "persistence": { @@ -100,14 +91,9 @@ func ResourcePoolV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { - value := v.(string) - if value != "SOURCE_IP" && value != "HTTP_COOKIE" && value != "APP_COOKIE" { - errors = append(errors, fmt.Errorf( - "Only 'SOURCE_IP', 'HTTP_COOKIE', and 'APP_COOKIE' are supported values for 'persistence'")) - } - return - }, + ValidateFunc: validation.StringInSlice([]string{ + "SOURCE_IP", "HTTP_COOKIE", "APP_COOKIE", + }, false), }, "cookie_name": { @@ -147,14 +133,13 @@ func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error { if persistence.Type == "APP_COOKIE" { if pV["cookie_name"].(string) == "" { return fmt.Errorf( - "Persistence cookie_name needs to be set if using 'APP_COOKIE' persistence type.") - } else { - persistence.CookieName = pV["cookie_name"].(string) + "Persistence cookie_name needs to be set if using 'APP_COOKIE' persistence type") } + persistence.CookieName = pV["cookie_name"].(string) } else { if pV["cookie_name"].(string) != "" { return fmt.Errorf( - "Persistence cookie_name can only be set if using 'APP_COOKIE' persistence type.") + "Persistence cookie_name can only be set if using 'APP_COOKIE' persistence type") } } }