diff --git a/.changelog/2127.txt b/.changelog/2127.txt new file mode 100644 index 0000000000..405f8973ce --- /dev/null +++ b/.changelog/2127.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_clb_listener: support create port range listener +``` diff --git a/tencentcloud/resource_tc_clb_listener.go b/tencentcloud/resource_tc_clb_listener.go index 3dc52cb531..de95ef2267 100644 --- a/tencentcloud/resource_tc_clb_listener.go +++ b/tencentcloud/resource_tc_clb_listener.go @@ -136,6 +136,27 @@ resource "tencentcloud_clb_listener" "TCPSSL_listener" { target_type = "TARGETGROUP" } ``` + +Port Range Listener + +```hcl +resource "tencentcloud_clb_instance" "clb_basic" { + network_type = "OPEN" + clb_name = "tf-listener-test" +} + +resource "tencentcloud_clb_listener" "listener_basic" { + clb_id = tencentcloud_clb_instance.clb_basic.id + port = 1 + end_port = 6 + protocol = "TCP" + listener_name = "listener_basic" + session_expire_time = 30 + scheduler = "WRR" + target_type = "NODE" +} +``` + Import CLB listener can be imported using the id (version >= 1.47.0), e.g. @@ -357,6 +378,13 @@ func resourceTencentCloudClbListener() *schema.Resource { ValidateFunc: validateAllowedStringValue([]string{CLB_TARGET_TYPE_NODE, CLB_TARGET_TYPE_TARGETGROUP}), Description: "Backend target type. Valid values: `NODE`, `TARGETGROUP`. `NODE` means to bind ordinary nodes, `TARGETGROUP` means to bind target group. NOTES: TCP/UDP/TCP_SSL listener must configuration, HTTP/HTTPS listener needs to be configured in tencentcloud_clb_listener_rule.", }, + "end_port": { + Type: schema.TypeInt, + ForceNew: true, + Computed: true, + Optional: true, + Description: "This parameter is used to specify the end port and is required when creating a port range listener. Only one member can be passed in when inputting the `Ports` parameter, which is used to specify the start port. If you want to try the port range feature, please [submit a ticket](https://console.cloud.tencent.com/workorder/category).", + }, //computed "listener_id": { Type: schema.TypeString, @@ -452,6 +480,10 @@ func resourceTencentCloudClbListenerCreate(d *schema.ResourceData, meta interfac request.SniSwitch = &vvv } } + if v, ok := d.GetOkExists("end_port"); ok { + request.EndPort = helper.IntUint64(v.(int)) + } + var response *clb.CreateListenerResponse err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { result, e := meta.(*TencentCloudClient).apiV3Conn.UseClbClient().CreateListener(request) @@ -606,6 +638,10 @@ func resourceTencentCloudClbListenerRead(d *schema.ResourceData, meta interface{ } } + if instance.EndPort != nil { + _ = d.Set("end_port", instance.EndPort) + } + return nil } diff --git a/tencentcloud/resource_tc_clb_listener_test.go b/tencentcloud/resource_tc_clb_listener_test.go index 9442b5f0aa..12a948b9c9 100644 --- a/tencentcloud/resource_tc_clb_listener_test.go +++ b/tencentcloud/resource_tc_clb_listener_test.go @@ -40,6 +40,36 @@ func TestAccTencentCloudClbListener_basic(t *testing.T) { }) } +func TestAccTencentCloudClbListenerResource_PortRange(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckClbListenerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccClbListener_portRange, + Check: resource.ComposeTestCheckFunc( + testAccCheckClbListenerExists("tencentcloud_clb_listener.listener_port_range"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_listener.listener_port_range", "clb_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "protocol", "TCP"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "listener_name", "listener_port_range"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "session_expire_time", "30"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "port", "1"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "end_port", "6"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "scheduler", "WRR"), + ), + }, + { + ResourceName: "tencentcloud_clb_listener.listener_port_range", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccTencentCloudClbListener_tcp_basic(t *testing.T) { t.Parallel() @@ -442,6 +472,24 @@ resource "tencentcloud_clb_listener" "listener_basic" { } ` +const testAccClbListener_portRange = ` +resource "tencentcloud_clb_instance" "clb_basic" { + network_type = "OPEN" + clb_name = "tf-clb-listener-port-range" +} + +resource "tencentcloud_clb_listener" "listener_port_range" { + clb_id = tencentcloud_clb_instance.clb_basic.id + port = 1 + end_port = 6 + protocol = "TCP" + listener_name = "listener_port_range" + session_expire_time = 30 + scheduler = "WRR" + target_type = "NODE" +} +` + const testAccClbListener_tcp = ` resource "tencentcloud_clb_instance" "clb_basic" { network_type = "OPEN" diff --git a/website/docs/r/clb_listener.html.markdown b/website/docs/r/clb_listener.html.markdown index ce93748e2a..f15e714b1a 100644 --- a/website/docs/r/clb_listener.html.markdown +++ b/website/docs/r/clb_listener.html.markdown @@ -150,6 +150,26 @@ resource "tencentcloud_clb_listener" "TCPSSL_listener" { } ``` +### Port Range Listener + +```hcl +resource "tencentcloud_clb_instance" "clb_basic" { + network_type = "OPEN" + clb_name = "tf-listener-test" +} + +resource "tencentcloud_clb_listener" "listener_basic" { + clb_id = tencentcloud_clb_instance.clb_basic.id + port = 1 + end_port = 6 + protocol = "TCP" + listener_name = "listener_basic" + session_expire_time = 30 + scheduler = "WRR" + target_type = "NODE" +} +``` + ## Argument Reference The following arguments are supported: @@ -160,6 +180,7 @@ The following arguments are supported: * `certificate_ca_id` - (Optional, String) ID of the client certificate. NOTES: Only supports listeners of `HTTPS` and `TCP_SSL` protocol and must be set when the ssl mode is `MUTUAL`. * `certificate_id` - (Optional, String) ID of the server certificate. NOTES: Only supports listeners of `HTTPS` and `TCP_SSL` protocol and must be set when it is available. * `certificate_ssl_mode` - (Optional, String) Type of certificate. Valid values: `UNIDIRECTIONAL`, `MUTUAL`. NOTES: Only supports listeners of `HTTPS` and `TCP_SSL` protocol and must be set when it is available. +* `end_port` - (Optional, Int, ForceNew) This parameter is used to specify the end port and is required when creating a port range listener. Only one member can be passed in when inputting the `Ports` parameter, which is used to specify the start port. If you want to try the port range feature, please [submit a ticket](https://console.cloud.tencent.com/workorder/category). * `health_check_context_type` - (Optional, String) Health check protocol. When the value of `health_check_type` of the health check protocol is `CUSTOM`, this field is required, which represents the input format of the health check. Valid values: `HEX`, `TEXT`. * `health_check_health_num` - (Optional, Int) Health threshold of health check, and the default is `3`. If a success result is returned for the health check for 3 consecutive times, the backend CVM is identified as healthy. The value range is 2-10. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in tencentcloud_clb_listener_rule. * `health_check_http_code` - (Optional, Int) HTTP health check code of TCP listener, Valid value ranges: [1~31]. When the value of `health_check_type` of the health check protocol is `HTTP`, this field is required. Valid values: `1`, `2`, `4`, `8`, `16`. `1` means http_1xx, `2` means http_2xx, `4` means http_3xx, `8` means http_4xx, `16` means http_5xx.If you want multiple return codes to indicate health, need to add the corresponding values.