Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenEarth committed Sep 15, 2023
2 parents a0f8d9e + 20ed4e0 commit 72a3c0e
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2127.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_clb_listener: support create port range listener
```
36 changes: 36 additions & 0 deletions tencentcloud/resource_tc_clb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -606,6 +638,10 @@ func resourceTencentCloudClbListenerRead(d *schema.ResourceData, meta interface{
}
}

if instance.EndPort != nil {
_ = d.Set("end_port", instance.EndPort)
}

return nil
}

Expand Down
48 changes: 48 additions & 0 deletions tencentcloud/resource_tc_clb_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions website/docs/r/clb_listener.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down

0 comments on commit 72a3c0e

Please sign in to comment.