diff --git a/.changelog/2405.txt b/.changelog/2405.txt new file mode 100644 index 0000000000..09639cf495 --- /dev/null +++ b/.changelog/2405.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_clb_listener: Add parameters `health_source_ip_type`, `session_type` and `keepalive_enable`. +``` \ No newline at end of file diff --git a/tencentcloud/extension_clb.go b/tencentcloud/extension_clb.go index 84e6c8c407..7d371abbc0 100644 --- a/tencentcloud/extension_clb.go +++ b/tencentcloud/extension_clb.go @@ -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" +) diff --git a/tencentcloud/resource_tc_clb_listener.go b/tencentcloud/resource_tc_clb_listener.go index bdbee324ea..790f189bd6 100644 --- a/tencentcloud/resource_tc_clb_listener.go +++ b/tencentcloud/resource_tc_clb_listener.go @@ -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, @@ -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, @@ -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)) } @@ -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 { @@ -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) } @@ -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) diff --git a/tencentcloud/service_tencentcloud_clb.go b/tencentcloud/service_tencentcloud_clb.go index 7101fea9c9..6de95df4c6 100644 --- a/tencentcloud/service_tencentcloud_clb.go +++ b/tencentcloud/service_tencentcloud_clb.go @@ -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) && diff --git a/website/docs/r/clb_listener.html.markdown b/website/docs/r/clb_listener.html.markdown index f15e714b1a..80ae8064ce 100644 --- a/website/docs/r/clb_listener.html.markdown +++ b/website/docs/r/clb_listener.html.markdown @@ -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.