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