@@ -783,159 +783,166 @@ func (me *ClbService) DeleteRedirectionById(ctx context.Context, rewriteId strin
783
783
784
784
func checkHealthCheckPara (ctx context.Context , d * schema.ResourceData , protocol string , applyType string ) (healthSetFlag bool , healthCheckPara * clb.HealthCheck , errRet error ) {
785
785
var healthCheck clb.HealthCheck
786
+ var checkType string
787
+
786
788
healthSetFlag = false
787
789
healthCheckPara = & healthCheck
790
+ healthSwitch := int64 (0 )
788
791
if v , ok := d .GetOkExists ("health_check_switch" ); ok {
789
792
healthSetFlag = true
790
793
vv := v .(bool )
791
- vvv := int64 (0 )
792
794
if vv {
793
- vvv = 1
794
- }
795
- healthCheck .HealthSwitch = & vvv
796
- }
797
- if v , ok := d .GetOk ("health_check_time_out" ); ok {
798
- healthSetFlag = true
799
- vv := int64 (v .(int ))
800
- healthCheck .TimeOut = & vv
801
- }
802
- if v , ok := d .GetOk ("health_check_interval_time" ); ok {
803
- healthSetFlag = true
804
- vv := int64 (v .(int ))
805
- healthCheck .IntervalTime = & vv
806
- }
807
- if v , ok := d .GetOk ("health_check_health_num" ); ok {
808
- healthSetFlag = true
809
- vv := int64 (v .(int ))
810
- healthCheck .HealthNum = & vv
811
- }
812
- if v , ok := d .GetOk ("health_check_unhealth_num" ); ok {
813
- healthSetFlag = true
814
- vv := int64 (v .(int ))
815
- healthCheck .UnHealthNum = & vv
816
- }
817
- if v , ok := d .GetOk ("health_check_port" ); ok {
818
- healthSetFlag = true
819
- healthCheck .CheckPort = helper .Int64 (int64 (v .(int )))
820
- }
821
- var checkType string
822
- if v , ok := d .GetOk ("health_check_type" ); ok {
823
- healthSetFlag = true
824
- checkType = v .(string )
825
- healthCheck .CheckType = & checkType
826
- }
827
- if v , ok := d .GetOk ("health_check_http_code" ); ok {
828
- if ! (protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
829
- (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP )) {
830
- healthSetFlag = false
831
- errRet = fmt .Errorf ("health_check_http_code can only be set with protocol HTTP/HTTPS or HTTP of TCP" )
832
- errRet = errors .WithStack (errRet )
833
- return
834
- }
835
- healthSetFlag = true
836
- healthCheck .HttpCode = helper .Int64 (int64 (v .(int )))
837
- }
838
- if v , ok := d .GetOk ("health_check_http_path" ); ok {
839
- if ! (protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
840
- (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP )) {
841
- healthSetFlag = false
842
- errRet = fmt .Errorf ("health_check_http_path can only be set with protocol HTTP/HTTPS or HTTP of TCP" )
843
- errRet = errors .WithStack (errRet )
844
- return
845
- }
846
- healthSetFlag = true
847
- healthCheck .HttpCheckPath = helper .String (v .(string ))
848
- }
849
- if v , ok := d .GetOk ("health_check_http_domain" ); ok {
850
- if ! (protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
851
- (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP )) {
852
- healthSetFlag = false
853
- errRet = fmt .Errorf ("health_check_http_domain can only be set with protocol HTTP/HTTPS or HTTP of TCP" )
854
- errRet = errors .WithStack (errRet )
855
- return
856
- }
857
- healthSetFlag = true
858
- healthCheck .HttpCheckDomain = helper .String (v .(string ))
859
- }
860
- if v , ok := d .GetOk ("health_check_http_method" ); ok {
861
- if ! (protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
862
- (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP )) {
863
- healthSetFlag = false
864
- errRet = fmt .Errorf ("health_check_http_method can only be set with protocol HTTP/HTTPS or HTTP of TCP" )
865
- errRet = errors .WithStack (errRet )
866
- return
867
- }
868
- healthSetFlag = true
869
- healthCheck .HttpCheckMethod = helper .String (v .(string ))
870
- }
871
- if v , ok := d .GetOk ("health_check_http_version" ); ok {
872
- if ! (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP ) {
873
- healthSetFlag = false
874
- errRet = fmt .Errorf ("health_check_http_version can only be set with protocol HTTP of TCP" )
875
- errRet = errors .WithStack (errRet )
876
- return
877
- }
878
- healthSetFlag = true
879
- healthCheck .HttpVersion = helper .String (v .(string ))
880
- }
881
- if v , ok := d .GetOk ("health_check_context_type" ); ok {
882
- if ! ((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP ) && checkType == HEALTH_CHECK_TYPE_CUSTOM ) {
883
- healthSetFlag = false
884
- errRet = fmt .Errorf ("health_check_context_type can only be set with protocol CUSTOM of TCP/UDP" )
885
- errRet = errors .WithStack (errRet )
886
- return
887
- }
888
- healthSetFlag = true
889
- healthCheck .ContextType = helper .String (v .(string ))
890
- }
891
- if v , ok := d .GetOk ("health_check_send_context" ); ok {
892
- if ! ((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP ) && checkType == HEALTH_CHECK_TYPE_CUSTOM ) {
893
- healthSetFlag = false
894
- errRet = fmt .Errorf ("health_check_send_context can only be set with protocol CUSTOM of TCP/UDP" )
895
- errRet = errors .WithStack (errRet )
896
- return
897
- }
898
- healthSetFlag = true
899
- healthCheck .SendContext = helper .String (v .(string ))
900
- }
901
- if v , ok := d .GetOk ("health_check_recv_context" ); ok {
902
- if ! ((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP ) && checkType == HEALTH_CHECK_TYPE_CUSTOM ) {
903
- healthSetFlag = false
904
- errRet = fmt .Errorf ("health_check_recv_context can only be set with protocol CUSTOM of TCP/UDP" )
905
- errRet = errors .WithStack (errRet )
906
- return
795
+ healthSwitch = 1
796
+ }
797
+ healthCheck .HealthSwitch = & healthSwitch
798
+ }
799
+ if IsHealthCheckEnable (healthSwitch ) {
800
+ if v , ok := d .GetOk ("health_check_time_out" ); ok {
801
+ healthSetFlag = true
802
+ vv := int64 (v .(int ))
803
+ healthCheck .TimeOut = & vv
804
+ }
805
+ if v , ok := d .GetOk ("health_check_interval_time" ); ok {
806
+ healthSetFlag = true
807
+ vv := int64 (v .(int ))
808
+ healthCheck .IntervalTime = & vv
809
+ }
810
+ if v , ok := d .GetOk ("health_check_health_num" ); ok {
811
+ healthSetFlag = true
812
+ vv := int64 (v .(int ))
813
+ healthCheck .HealthNum = & vv
814
+ }
815
+ if v , ok := d .GetOk ("health_check_unhealth_num" ); ok {
816
+ healthSetFlag = true
817
+ vv := int64 (v .(int ))
818
+ healthCheck .UnHealthNum = & vv
819
+ }
820
+ if v , ok := d .GetOk ("health_check_port" ); ok {
821
+ healthSetFlag = true
822
+ healthCheck .CheckPort = helper .Int64 (int64 (v .(int )))
823
+ }
824
+
825
+ if v , ok := d .GetOk ("health_check_type" ); ok {
826
+ healthSetFlag = true
827
+ checkType = v .(string )
828
+ healthCheck .CheckType = & checkType
829
+ }
830
+ if v , ok := d .GetOk ("health_check_http_code" ); ok {
831
+ if ! (protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
832
+ (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP )) {
833
+ healthSetFlag = false
834
+ errRet = fmt .Errorf ("health_check_http_code can only be set with protocol HTTP/HTTPS or HTTP of TCP" )
835
+ errRet = errors .WithStack (errRet )
836
+ return
837
+ }
838
+ healthSetFlag = true
839
+ healthCheck .HttpCode = helper .Int64 (int64 (v .(int )))
840
+ }
841
+ if v , ok := d .GetOk ("health_check_http_path" ); ok {
842
+ if ! (protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
843
+ (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP )) {
844
+ healthSetFlag = false
845
+ errRet = fmt .Errorf ("health_check_http_path can only be set with protocol HTTP/HTTPS or HTTP of TCP" )
846
+ errRet = errors .WithStack (errRet )
847
+ return
848
+ }
849
+ healthSetFlag = true
850
+ healthCheck .HttpCheckPath = helper .String (v .(string ))
851
+ }
852
+ if v , ok := d .GetOk ("health_check_http_domain" ); ok {
853
+ if ! (protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
854
+ (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP )) {
855
+ healthSetFlag = false
856
+ errRet = fmt .Errorf ("health_check_http_domain can only be set with protocol HTTP/HTTPS or HTTP of TCP" )
857
+ errRet = errors .WithStack (errRet )
858
+ return
859
+ }
860
+ healthSetFlag = true
861
+ healthCheck .HttpCheckDomain = helper .String (v .(string ))
862
+ }
863
+ if v , ok := d .GetOk ("health_check_http_method" ); ok {
864
+ if ! (protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ||
865
+ (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP )) {
866
+ healthSetFlag = false
867
+ errRet = fmt .Errorf ("health_check_http_method can only be set with protocol HTTP/HTTPS or HTTP of TCP" )
868
+ errRet = errors .WithStack (errRet )
869
+ return
870
+ }
871
+ healthSetFlag = true
872
+ healthCheck .HttpCheckMethod = helper .String (v .(string ))
873
+ }
874
+ if v , ok := d .GetOk ("health_check_http_version" ); ok {
875
+ if ! (protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_HTTP ) {
876
+ healthSetFlag = false
877
+ errRet = fmt .Errorf ("health_check_http_version can only be set with protocol HTTP of TCP" )
878
+ errRet = errors .WithStack (errRet )
879
+ return
880
+ }
881
+ healthSetFlag = true
882
+ healthCheck .HttpVersion = helper .String (v .(string ))
883
+ }
884
+ if v , ok := d .GetOk ("health_check_context_type" ); ok {
885
+ if ! ((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP ) && checkType == HEALTH_CHECK_TYPE_CUSTOM ) {
886
+ healthSetFlag = false
887
+ errRet = fmt .Errorf ("health_check_context_type can only be set with protocol CUSTOM of TCP/UDP" )
888
+ errRet = errors .WithStack (errRet )
889
+ return
890
+ }
891
+ healthSetFlag = true
892
+ healthCheck .ContextType = helper .String (v .(string ))
893
+ }
894
+ if v , ok := d .GetOk ("health_check_send_context" ); ok {
895
+ if ! ((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP ) && checkType == HEALTH_CHECK_TYPE_CUSTOM ) {
896
+ healthSetFlag = false
897
+ errRet = fmt .Errorf ("health_check_send_context can only be set with protocol CUSTOM of TCP/UDP" )
898
+ errRet = errors .WithStack (errRet )
899
+ return
900
+ }
901
+ healthSetFlag = true
902
+ healthCheck .SendContext = helper .String (v .(string ))
903
+ }
904
+ if v , ok := d .GetOk ("health_check_recv_context" ); ok {
905
+ if ! ((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP ) && checkType == HEALTH_CHECK_TYPE_CUSTOM ) {
906
+ healthSetFlag = false
907
+ errRet = fmt .Errorf ("health_check_recv_context can only be set with protocol CUSTOM of TCP/UDP" )
908
+ errRet = errors .WithStack (errRet )
909
+ return
910
+ }
911
+ healthSetFlag = true
912
+ healthCheck .RecvContext = helper .String (v .(string ))
907
913
}
908
- healthSetFlag = true
909
- healthCheck .RecvContext = helper .String (v .(string ))
910
- }
911
914
912
- if v , ok := d .GetOk ("health_source_ip_type" ); ok {
913
- healthSetFlag = true
914
- healthCheck .SourceIpType = helper .Int64 (int64 (v .(int )))
915
+ if v , ok := d .GetOk ("health_source_ip_type" ); ok {
916
+ healthSetFlag = true
917
+ healthCheck .SourceIpType = helper .Int64 (int64 (v .(int )))
918
+ }
915
919
}
916
920
917
921
if healthSetFlag {
918
- if ! (((protocol == CLB_LISTENER_PROTOCOL_TCP || protocol == CLB_LISTENER_PROTOCOL_UDP ||
919
- protocol == CLB_LISTENER_PROTOCOL_TCPSSL || protocol == CLB_LISTENER_PROTOCOL_QUIC ) &&
920
- applyType == HEALTH_APPLY_TYPE_LISTENER ) ||
921
- ((protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ) &&
922
- applyType == HEALTH_APPLY_TYPE_RULE )) {
923
- healthSetFlag = false
924
- errRet = fmt .Errorf ("health para can only be set with TCP/UDP/TCP_SSL listener or rule of HTTP/HTTPS listener" )
925
- errRet = errors .WithStack (errRet )
926
- return
927
- }
928
- if protocol == CLB_LISTENER_PROTOCOL_TCP {
929
- if checkType == HEALTH_CHECK_TYPE_HTTP && healthCheck .HttpCheckDomain == nil {
930
- healthCheck .HttpCheckDomain = helper .String ("" )
931
- }
932
- if healthCheck .CheckPort == nil {
933
- healthCheck .CheckPort = helper .Int64 (- 1 )
922
+ if IsHealthCheckEnable (healthSwitch ) {
923
+ if ! (((protocol == CLB_LISTENER_PROTOCOL_TCP || protocol == CLB_LISTENER_PROTOCOL_UDP ||
924
+ protocol == CLB_LISTENER_PROTOCOL_TCPSSL || protocol == CLB_LISTENER_PROTOCOL_QUIC ) &&
925
+ applyType == HEALTH_APPLY_TYPE_LISTENER ) ||
926
+ ((protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS ) &&
927
+ applyType == HEALTH_APPLY_TYPE_RULE )) {
928
+ healthSetFlag = false
929
+ errRet = fmt .Errorf ("health para can only be set with TCP/UDP/TCP_SSL listener or rule of HTTP/HTTPS listener" )
930
+ errRet = errors .WithStack (errRet )
931
+ return
934
932
}
935
- if healthCheck .HttpCheckPath == nil {
936
- healthCheck .HttpCheckPath = helper .String ("" )
933
+ if protocol == CLB_LISTENER_PROTOCOL_TCP {
934
+ if checkType == HEALTH_CHECK_TYPE_HTTP && healthCheck .HttpCheckDomain == nil {
935
+ healthCheck .HttpCheckDomain = helper .String ("" )
936
+ }
937
+ if healthCheck .CheckPort == nil {
938
+ healthCheck .CheckPort = helper .Int64 (- 1 )
939
+ }
940
+ if healthCheck .HttpCheckPath == nil {
941
+ healthCheck .HttpCheckPath = helper .String ("" )
942
+ }
937
943
}
938
944
}
945
+
939
946
healthCheckPara = & healthCheck
940
947
}
941
948
return
@@ -2345,3 +2352,6 @@ func (me *ClbService) DescribeClbTargetGroupAttachmentsById(ctx context.Context,
2345
2352
targetGroupAttachments = result
2346
2353
return
2347
2354
}
2355
+ func IsHealthCheckEnable (healthSwitch int64 ) bool {
2356
+ return healthSwitch == int64 (1 )
2357
+ }
0 commit comments