Skip to content

Commit 20ed4e0

Browse files
authored
Merge pull request #2127 from tencentcloudstack/feat/add_end_port
support end port
2 parents d227392 + ed8a830 commit 20ed4e0

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

.changelog/2127.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_clb_listener: support create port range listener
3+
```

tencentcloud/resource_tc_clb_listener.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ resource "tencentcloud_clb_listener" "TCPSSL_listener" {
136136
target_type = "TARGETGROUP"
137137
}
138138
```
139+
140+
Port Range Listener
141+
142+
```hcl
143+
resource "tencentcloud_clb_instance" "clb_basic" {
144+
network_type = "OPEN"
145+
clb_name = "tf-listener-test"
146+
}
147+
148+
resource "tencentcloud_clb_listener" "listener_basic" {
149+
clb_id = tencentcloud_clb_instance.clb_basic.id
150+
port = 1
151+
end_port = 6
152+
protocol = "TCP"
153+
listener_name = "listener_basic"
154+
session_expire_time = 30
155+
scheduler = "WRR"
156+
target_type = "NODE"
157+
}
158+
```
159+
139160
Import
140161
141162
CLB listener can be imported using the id (version >= 1.47.0), e.g.
@@ -357,6 +378,13 @@ func resourceTencentCloudClbListener() *schema.Resource {
357378
ValidateFunc: validateAllowedStringValue([]string{CLB_TARGET_TYPE_NODE, CLB_TARGET_TYPE_TARGETGROUP}),
358379
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.",
359380
},
381+
"end_port": {
382+
Type: schema.TypeInt,
383+
ForceNew: true,
384+
Computed: true,
385+
Optional: true,
386+
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).",
387+
},
360388
//computed
361389
"listener_id": {
362390
Type: schema.TypeString,
@@ -452,6 +480,10 @@ func resourceTencentCloudClbListenerCreate(d *schema.ResourceData, meta interfac
452480
request.SniSwitch = &vvv
453481
}
454482
}
483+
if v, ok := d.GetOkExists("end_port"); ok {
484+
request.EndPort = helper.IntUint64(v.(int))
485+
}
486+
455487
var response *clb.CreateListenerResponse
456488
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
457489
result, e := meta.(*TencentCloudClient).apiV3Conn.UseClbClient().CreateListener(request)
@@ -606,6 +638,10 @@ func resourceTencentCloudClbListenerRead(d *schema.ResourceData, meta interface{
606638
}
607639
}
608640

641+
if instance.EndPort != nil {
642+
_ = d.Set("end_port", instance.EndPort)
643+
}
644+
609645
return nil
610646
}
611647

tencentcloud/resource_tc_clb_listener_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,36 @@ func TestAccTencentCloudClbListener_basic(t *testing.T) {
4040
})
4141
}
4242

43+
func TestAccTencentCloudClbListenerResource_PortRange(t *testing.T) {
44+
t.Parallel()
45+
46+
resource.Test(t, resource.TestCase{
47+
PreCheck: func() { testAccPreCheck(t) },
48+
Providers: testAccProviders,
49+
CheckDestroy: testAccCheckClbListenerDestroy,
50+
Steps: []resource.TestStep{
51+
{
52+
Config: testAccClbListener_portRange,
53+
Check: resource.ComposeTestCheckFunc(
54+
testAccCheckClbListenerExists("tencentcloud_clb_listener.listener_port_range"),
55+
resource.TestCheckResourceAttrSet("tencentcloud_clb_listener.listener_port_range", "clb_id"),
56+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "protocol", "TCP"),
57+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "listener_name", "listener_port_range"),
58+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "session_expire_time", "30"),
59+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "port", "1"),
60+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "end_port", "6"),
61+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_port_range", "scheduler", "WRR"),
62+
),
63+
},
64+
{
65+
ResourceName: "tencentcloud_clb_listener.listener_port_range",
66+
ImportState: true,
67+
ImportStateVerify: true,
68+
},
69+
},
70+
})
71+
}
72+
4373
func TestAccTencentCloudClbListener_tcp_basic(t *testing.T) {
4474
t.Parallel()
4575

@@ -442,6 +472,24 @@ resource "tencentcloud_clb_listener" "listener_basic" {
442472
}
443473
`
444474

475+
const testAccClbListener_portRange = `
476+
resource "tencentcloud_clb_instance" "clb_basic" {
477+
network_type = "OPEN"
478+
clb_name = "tf-clb-listener-port-range"
479+
}
480+
481+
resource "tencentcloud_clb_listener" "listener_port_range" {
482+
clb_id = tencentcloud_clb_instance.clb_basic.id
483+
port = 1
484+
end_port = 6
485+
protocol = "TCP"
486+
listener_name = "listener_port_range"
487+
session_expire_time = 30
488+
scheduler = "WRR"
489+
target_type = "NODE"
490+
}
491+
`
492+
445493
const testAccClbListener_tcp = `
446494
resource "tencentcloud_clb_instance" "clb_basic" {
447495
network_type = "OPEN"

website/docs/r/clb_listener.html.markdown

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,26 @@ resource "tencentcloud_clb_listener" "TCPSSL_listener" {
150150
}
151151
```
152152

153+
### Port Range Listener
154+
155+
```hcl
156+
resource "tencentcloud_clb_instance" "clb_basic" {
157+
network_type = "OPEN"
158+
clb_name = "tf-listener-test"
159+
}
160+
161+
resource "tencentcloud_clb_listener" "listener_basic" {
162+
clb_id = tencentcloud_clb_instance.clb_basic.id
163+
port = 1
164+
end_port = 6
165+
protocol = "TCP"
166+
listener_name = "listener_basic"
167+
session_expire_time = 30
168+
scheduler = "WRR"
169+
target_type = "NODE"
170+
}
171+
```
172+
153173
## Argument Reference
154174

155175
The following arguments are supported:
@@ -160,6 +180,7 @@ The following arguments are supported:
160180
* `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`.
161181
* `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.
162182
* `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.
183+
* `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).
163184
* `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`.
164185
* `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.
165186
* `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.

0 commit comments

Comments
 (0)