diff --git a/.changelog/3045.txt b/.changelog/3045.txt new file mode 100644 index 0000000000..8473921d0d --- /dev/null +++ b/.changelog/3045.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_clb_listener_rule: support `health_check_port` +``` diff --git a/tencentcloud/services/clb/resource_tc_clb_listener_rule.go b/tencentcloud/services/clb/resource_tc_clb_listener_rule.go index 3bf22eefba..c5bb6de780 100644 --- a/tencentcloud/services/clb/resource_tc_clb_listener_rule.go +++ b/tencentcloud/services/clb/resource_tc_clb_listener_rule.go @@ -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, @@ -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") } @@ -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 }) @@ -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 { @@ -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) } diff --git a/tencentcloud/services/clb/service_tencentcloud_clb.go b/tencentcloud/services/clb/service_tencentcloud_clb.go index 65d3998f5a..4c9ff9fa07 100644 --- a/tencentcloud/services/clb/service_tencentcloud_clb.go +++ b/tencentcloud/services/clb/service_tencentcloud_clb.go @@ -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))) } @@ -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 @@ -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))) } diff --git a/website/docs/r/clb_listener_rule.html.markdown b/website/docs/r/clb_listener_rule.html.markdown index cb0579cfbd..69fb3572c3 100644 --- a/website/docs/r/clb_listener_rule.html.markdown +++ b/website/docs/r/clb_listener_rule.html.markdown @@ -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`.