Skip to content

add listener param #2405

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

Merged
merged 2 commits into from
Dec 15, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2405.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_clb_listener: Add parameters `health_source_ip_type`, `session_type` and `keepalive_enable`.
```
5 changes: 5 additions & 0 deletions tencentcloud/extension_clb.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ const (
CLB_BACKEND_TYPE_CVM = "CVM"
CLB_BACKEND_TYPE_ENI = "ENI"
)

const (
CLB_SESSION_TYPE_NORMAL = "NORMAL"
CLB_SESSION_TYPE_QUIC = "QUIC_CID"
)
51 changes: 51 additions & 0 deletions tencentcloud/resource_tc_clb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ func resourceTencentCloudClbListener() *schema.Resource {
"the characters of SendContext and RecvContext can only be selected in `0123456789ABCDEF` " +
"and the length must be even digits.",
},
"health_source_ip_type": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validateAllowedIntValue([]int{0, 1}),
Description: "Specifies the type of health check source IP. `0` (default): CLB VIP. `1`: 100.64 IP range.",
},
"certificate_ssl_mode": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -211,6 +218,19 @@ 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.",
},
"session_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateAllowedStringValue([]string{CLB_SESSION_TYPE_NORMAL, CLB_SESSION_TYPE_QUIC}),
Description: "Session persistence type. Valid values: `NORMAL`: the default session persistence type; `QUIC_CID`: session persistence by QUIC connection ID. The `QUIC_CID` value can only be configured in UDP listeners. If this field is not specified, the default session persistence type will be used.",
},
"keepalive_enable": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Whether to enable a persistent connection. This parameter is applicable only to HTTP and HTTPS listeners. Valid values: 0 (disable; default value) and 1 (enable).",
},
"end_port": {
Type: schema.TypeInt,
ForceNew: true,
Expand Down Expand Up @@ -313,6 +333,15 @@ func resourceTencentCloudClbListenerCreate(d *schema.ResourceData, meta interfac
request.SniSwitch = &vvv
}
}

if v, ok := d.GetOk("session_type"); ok {
request.SessionType = helper.String(v.(string))
}

if v, ok := d.GetOkExists("keepalive_enable"); ok {
request.KeepaliveEnable = helper.IntInt64(v.(int))
}

if v, ok := d.GetOkExists("end_port"); ok {
request.EndPort = helper.IntUint64(v.(int))
}
Expand Down Expand Up @@ -461,6 +490,9 @@ func resourceTencentCloudClbListenerRead(d *schema.ResourceData, meta interface{
if instance.HealthCheck.RecvContext != nil {
_ = d.Set("health_check_recv_context", instance.HealthCheck.RecvContext)
}
if instance.HealthCheck.SourceIpType != nil {
_ = d.Set("health_source_ip_type", instance.HealthCheck.SourceIpType)
}
}

if instance.Certificate != nil {
Expand All @@ -471,6 +503,13 @@ func resourceTencentCloudClbListenerRead(d *schema.ResourceData, meta interface{
}
}

if instance.SessionType != nil {
_ = d.Set("session_type", instance.SessionType)
}
if instance.KeepaliveEnable != nil {
_ = d.Set("keepalive_enable", instance.KeepaliveEnable)
}

if instance.EndPort != nil {
_ = d.Set("end_port", instance.EndPort)
}
Expand Down Expand Up @@ -556,6 +595,18 @@ func resourceTencentCloudClbListenerUpdate(d *schema.ResourceData, meta interfac
request.TargetType = helper.String(targetType)
}

if d.HasChange("session_type") {
changed = true
sessionType := d.Get("session_type").(string)
request.SessionType = helper.String(sessionType)
}

if d.HasChange("keepalive_enable") {
changed = true
keepaliveEnable := d.Get("keepalive_enable").(int)
request.KeepaliveEnable = helper.IntInt64(keepaliveEnable)
}

if changed {
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
response, e := meta.(*TencentCloudClient).apiV3Conn.UseClbClient().ModifyListener(request)
Expand Down
5 changes: 5 additions & 0 deletions tencentcloud/service_tencentcloud_clb.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,11 @@ func checkHealthCheckPara(ctx context.Context, d *schema.ResourceData, protocol
healthCheck.RecvContext = helper.String(v.(string))
}

if v, ok := d.GetOk("health_source_ip_type"); ok {
healthSetFlag = true
healthCheck.SourceIpType = helper.Int64(int64(v.(int)))
}

if healthSetFlag {
if !(((protocol == CLB_LISTENER_PROTOCOL_TCP || protocol == CLB_LISTENER_PROTOCOL_UDP ||
protocol == CLB_LISTENER_PROTOCOL_TCPSSL || protocol == CLB_LISTENER_PROTOCOL_QUIC) &&
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/clb_listener.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,12 @@ The following arguments are supported:
* `health_check_time_out` - (Optional, Int) Response timeout of health check. Valid value ranges: [2~60] sec. Default is 2 sec. Response timeout needs to be less than check interval. NOTES: Only supports listeners of `TCP`,`UDP`,`TCP_SSL` protocol.
* `health_check_type` - (Optional, String) Protocol used for health check. Valid values: `CUSTOM`, `TCP`, `HTTP`.
* `health_check_unhealth_num` - (Optional, Int) Unhealthy threshold of health check, and the default is `3`. If a success result is returned for the health check 3 consecutive times, the CVM is identified as unhealthy. 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_source_ip_type` - (Optional, Int) Specifies the type of health check source IP. `0` (default): CLB VIP. `1`: 100.64 IP range.
* `keepalive_enable` - (Optional, Int) Whether to enable a persistent connection. This parameter is applicable only to HTTP and HTTPS listeners. Valid values: 0 (disable; default value) and 1 (enable).
* `port` - (Optional, Int, ForceNew) Port of the CLB listener.
* `scheduler` - (Optional, String) Scheduling method of the CLB listener, and available values are 'WRR' and 'LEAST_CONN'. The default is 'WRR'. NOTES: The listener of `HTTP` and `HTTPS` protocol additionally supports the `IP Hash` method. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in `tencentcloud_clb_listener_rule`.
* `session_expire_time` - (Optional, Int) Time of session persistence within the CLB listener. NOTES: Available when scheduler is specified as `WRR`, and not available when listener protocol is `TCP_SSL`. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in `tencentcloud_clb_listener_rule`.
* `session_type` - (Optional, String) Session persistence type. Valid values: `NORMAL`: the default session persistence type; `QUIC_CID`: session persistence by QUIC connection ID. The `QUIC_CID` value can only be configured in UDP listeners. If this field is not specified, the default session persistence type will be used.
* `sni_switch` - (Optional, Bool, ForceNew) Indicates whether SNI is enabled, and only supported with protocol `HTTPS`. If enabled, you can set a certificate for each rule in `tencentcloud_clb_listener_rule`, otherwise all rules have a certificate.
* `target_type` - (Optional, String) 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.

Expand Down