@@ -56,9 +56,7 @@ func (me *ClbService) DescribeLoadBalancerById(ctx context.Context, clbId string
56
56
request := clb .NewDescribeLoadBalancersRequest ()
57
57
request .LoadBalancerIds = []* string {& clbId }
58
58
ratelimit .Check (request .GetAction ())
59
- var iacExtInfo connectivity.IacExtInfo
60
- iacExtInfo .InstanceId = clbId
61
- response , err := me .client .UseClbClient (iacExtInfo ).DescribeLoadBalancers (request )
59
+ response , err := me .client .UseClbClient ().DescribeLoadBalancers (request )
62
60
if err != nil {
63
61
errRet = errors .WithStack (err )
64
62
return
@@ -783,159 +781,166 @@ func (me *ClbService) DeleteRedirectionById(ctx context.Context, rewriteId strin
783
781
784
782
func checkHealthCheckPara (ctx context.Context , d * schema.ResourceData , protocol string , applyType string ) (healthSetFlag bool , healthCheckPara * clb.HealthCheck , errRet error ) {
785
783
var healthCheck clb.HealthCheck
784
+ var checkType string
785
+
786
786
healthSetFlag = false
787
787
healthCheckPara = & healthCheck
788
+ healthSwitch := int64 (0 )
788
789
if v , ok := d .GetOkExists ("health_check_switch" ); ok {
789
790
healthSetFlag = true
790
791
vv := v .(bool )
791
- vvv := int64 (0 )
792
792
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
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 ))
907
911
}
908
- healthSetFlag = true
909
- healthCheck .RecvContext = helper .String (v .(string ))
910
- }
911
912
912
- if v , ok := d .GetOk ("health_source_ip_type" ); ok {
913
- healthSetFlag = true
914
- 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
+ }
915
917
}
916
918
917
919
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 )
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
934
930
}
935
- if healthCheck .HttpCheckPath == nil {
936
- 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
+ }
937
941
}
938
942
}
943
+
939
944
healthCheckPara = & healthCheck
940
945
}
941
946
return
@@ -2345,3 +2350,6 @@ func (me *ClbService) DescribeClbTargetGroupAttachmentsById(ctx context.Context,
2345
2350
targetGroupAttachments = result
2346
2351
return
2347
2352
}
2353
+ func IsHealthCheckEnable (healthSwitch int64 ) bool {
2354
+ return healthSwitch == int64 (1 )
2355
+ }
0 commit comments