Skip to content

fix(clb): [121420044] tencentcloud_clb_listener_rule support health_check_port #3045

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 27, 2024
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/3045.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_clb_listener_rule: support `health_check_port`
```
16 changes: 14 additions & 2 deletions tencentcloud/services/clb/resource_tc_clb_listener_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func ResourceTencentCloudClbListenerRule() *schema.Resource {
ValidateFunc: tccommon.ValidateIntegerInRange(2, 10),
Description: "Unhealthy threshold of health check, and the default is `3`. If the unhealthy result is returned 3 consecutive times, indicates that the forwarding is abnormal. 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_port": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Customize detection related parameters. Health check port, defaults to the port of the backend service, unless you want to specify a specific port, it is recommended to leave it blank. (Applicable only to TCP/UDP listeners).",
},
"health_check_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -299,7 +305,7 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte
rule.Scheduler = helper.String(scheduler)
}

if v, ok := d.GetOk("session_expire_time"); ok {
if v, ok := d.GetOkExists("session_expire_time"); ok {
if !(protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS) {
return fmt.Errorf("[CHECK][CLB listener rule][Create] check: session_expire_time can only be set with protocol TCP/UDP or rule of listener HTTP/HTTPS")
}
Expand Down Expand Up @@ -368,6 +374,11 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte
if ruleErr != nil {
return tccommon.RetryError(errors.WithStack(ruleErr))
}

if ruleInstance == nil || ruleInstance.LocationId == nil {
return resource.NonRetryableError(fmt.Errorf("read CLB listener rule failed, Response is nil."))
}

locationId = *ruleInstance.LocationId
return nil
})
Expand All @@ -377,7 +388,7 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte
}

//this ID style changes since terraform 1.47.0
d.SetId(clbId + tccommon.FILED_SP + listenerId + tccommon.FILED_SP + locationId)
d.SetId(strings.Join([]string{clbId, listenerId, locationId}, tccommon.FILED_SP))

// set http2
if v, ok := d.GetOkExists("http2_switch"); ok {
Expand Down Expand Up @@ -559,6 +570,7 @@ func resourceTencentCloudClbListenerRuleRead(d *schema.ResourceData, meta interf
_ = d.Set("health_check_http_domain", instance.HealthCheck.HttpCheckDomain)
_ = d.Set("health_check_http_path", instance.HealthCheck.HttpCheckPath)
_ = d.Set("health_check_http_code", instance.HealthCheck.HttpCode)
_ = d.Set("health_check_port", instance.HealthCheck.CheckPort)
_ = d.Set("health_check_type", instance.HealthCheck.CheckType)
_ = d.Set("health_check_time_out", instance.HealthCheck.TimeOut)
}
Expand Down
14 changes: 7 additions & 7 deletions tencentcloud/services/clb/service_tencentcloud_clb.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,27 +863,27 @@ func checkHealthCheckPara(ctx context.Context, d *schema.ResourceData, protocol
healthCheck.HealthSwitch = &healthSwitch
}
if IsHealthCheckEnable(healthSwitch) {
if v, ok := d.GetOk("health_check_time_out"); ok {
if v, ok := d.GetOkExists("health_check_time_out"); ok {
healthSetFlag = true
vv := int64(v.(int))
healthCheck.TimeOut = &vv
}
if v, ok := d.GetOk("health_check_interval_time"); ok {
if v, ok := d.GetOkExists("health_check_interval_time"); ok {
healthSetFlag = true
vv := int64(v.(int))
healthCheck.IntervalTime = &vv
}
if v, ok := d.GetOk("health_check_health_num"); ok {
if v, ok := d.GetOkExists("health_check_health_num"); ok {
healthSetFlag = true
vv := int64(v.(int))
healthCheck.HealthNum = &vv
}
if v, ok := d.GetOk("health_check_unhealth_num"); ok {
if v, ok := d.GetOkExists("health_check_unhealth_num"); ok {
healthSetFlag = true
vv := int64(v.(int))
healthCheck.UnHealthNum = &vv
}
if v, ok := d.GetOk("health_check_port"); ok {
if v, ok := d.GetOkExists("health_check_port"); ok {
healthSetFlag = true
healthCheck.CheckPort = helper.Int64(int64(v.(int)))
}
Expand All @@ -893,7 +893,7 @@ func checkHealthCheckPara(ctx context.Context, d *schema.ResourceData, protocol
checkType = v.(string)
healthCheck.CheckType = &checkType
}
if v, ok := d.GetOk("health_check_http_code"); ok {
if v, ok := d.GetOkExists("health_check_http_code"); ok {
if !(protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
(protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP)) {
healthSetFlag = false
Expand Down Expand Up @@ -978,7 +978,7 @@ 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 {
if v, ok := d.GetOkExists("health_source_ip_type"); ok {
healthSetFlag = true
healthCheck.SourceIpType = helper.Int64(int64(v.(int)))
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/clb_listener_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The following arguments are supported:
* `health_check_http_method` - (Optional, String) Methods of health check. NOTES: Only supports listeners of `HTTP` and `HTTPS` protocol. The default is `HEAD`, the available value are `HEAD` and `GET`.
* `health_check_http_path` - (Optional, String) Path of health check. NOTES: Only supports listeners of `HTTP` and `HTTPS` protocol.
* `health_check_interval_time` - (Optional, Int) Interval time of health check. Valid value ranges: (2~300) sec. and the default is `5` sec. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in `tencentcloud_clb_listener_rule`.
* `health_check_port` - (Optional, Int) Customize detection related parameters. Health check port, defaults to the port of the backend service, unless you want to specify a specific port, it is recommended to leave it blank. (Applicable only to TCP/UDP listeners).
* `health_check_switch` - (Optional, Bool) Indicates whether health check is enabled.
* `health_check_time_out` - (Optional, Int) Time out of health check. The value range is [2-60](SEC).
* `health_check_type` - (Optional, String) Type of health check. Valid value is `CUSTOM`, `PING`, `TCP`, `HTTP`, `HTTPS`, `GRPC`, `GRPCS`.
Expand Down
Loading