Skip to content

Commit b63a749

Browse files
authored
Feat/clb health check type (#2496)
* fix: health check type * fix: health check type * fix: health check type * fix: health check type * fix: health check type
1 parent 19c714a commit b63a749

File tree

13 files changed

+2562
-1461
lines changed

13 files changed

+2562
-1461
lines changed

.changelog/2496.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_clb_listener: Support UDP health detection and handle the problem of COSTOM returning to default value
3+
```
4+

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ require (
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam v1.0.695
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748
46-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693
46+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
49-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.845
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.847
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748 h1:rVvR
866866
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748/go.mod h1:nvb4W+PgsAe8NFG1ZevZa9ZLfto3aeBcJqxzYCRI9V4=
867867
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693 h1:3eI2Ciq3NOXgoxeW/eY6vgCzi8vcqEZv+FzHww6K9oU=
868868
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693/go.mod h1:WhFqrn14QuRHB01xA5Q9sC+xw73BpqSE5+ZnqEznCW8=
869+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847 h1:VfUval30/CDPnvS5KpvTpM6v7HcErCgwPTsyN9VDqpM=
870+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847/go.mod h1:zR4WM8Cg+v4daLgPLfmmzFrXCQFrQYIn+7DqBL60uRc=
869871
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544 h1:ApY6rS7I9otgujOdAFy0+Epno1PNVCQmsOoWQxx724Y=
870872
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544/go.mod h1:c37rIdL3LrJXYwrfp9c8L4MabTqKIZUe1xvnWhN75oc=
871873
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711 h1:v6ffPkv3kmT6bC0d3JLVVJsh61zdvaLJZ5RHwmKNBHk=
@@ -948,6 +950,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.841/go.mod
948950
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.843/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
949951
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.845 h1:fiiVD3+m2gJFQItUomuJ7OpXHKyULTDu0LDZ/iOKI4A=
950952
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.845/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
953+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.847 h1:ITZmxAWfbr5yikJ4T30yVYMW3jpa/oTmNbPnw/h1Vq0=
954+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.847/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
951955
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
952956
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
953957
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 h1:2egy69SP/wPsmnfozcQVZ6tUY6F6N/TpEe/7xtXrc/8=

tencentcloud/services/clb/extension_clb.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,20 @@ var HTTP_VERSION = []string{
6262

6363
const (
6464
HEALTH_CHECK_TYPE_CUSTOM = "CUSTOM"
65+
HEALTH_CHECK_TYPE_PING = "PING"
6566
HEALTH_CHECK_TYPE_TCP = "TCP"
6667
HEALTH_CHECK_TYPE_HTTP = "HTTP"
68+
HEALTH_CHECK_TYPE_HTTPS = "HTTPS"
69+
HEALTH_CHECK_TYPE_GRPC = "GRPC"
6770
)
6871

6972
var HEALTH_CHECK_TYPE = []string{
7073
HEALTH_CHECK_TYPE_CUSTOM,
74+
HEALTH_CHECK_TYPE_PING,
7175
HEALTH_CHECK_TYPE_TCP,
7276
HEALTH_CHECK_TYPE_HTTP,
77+
HEALTH_CHECK_TYPE_HTTPS,
78+
HEALTH_CHECK_TYPE_GRPC,
7379
}
7480

7581
const (

tencentcloud/services/clb/resource_tc_clb_listener.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func ResourceTencentCloudClbListener() *schema.Resource {
9898
Optional: true,
9999
Computed: true,
100100
ValidateFunc: tccommon.ValidateAllowedStringValue(HEALTH_CHECK_TYPE),
101-
Description: "Protocol used for health check. Valid values: `CUSTOM`, `TCP`, `HTTP`.",
101+
Description: "Protocol used for health check. Valid values: `CUSTOM`, `TCP`, `HTTP`,`HTTPS`, `PING`, `GRPC`.",
102102
},
103103
"health_check_port": {
104104
Type: schema.TypeInt,
@@ -145,6 +145,7 @@ func ResourceTencentCloudClbListener() *schema.Resource {
145145
"health_check_context_type": {
146146
Type: schema.TypeString,
147147
Optional: true,
148+
Computed: true,
148149
ValidateFunc: tccommon.ValidateAllowedStringValue(CONTEX_TYPE),
149150
Description: "Health check protocol. When the value of `health_check_type` of the health check protocol is `CUSTOM`, " +
150151
"this field is required, which represents the input format of the health check. " +

tencentcloud/services/clb/resource_tc_clb_listener_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,47 @@ func TestAccTencentCloudClbListener_tcpssl(t *testing.T) {
396396
},
397397
})
398398
}
399+
func TestAccTencentCloudClbListener_udp(t *testing.T) {
400+
t.Parallel()
399401

402+
resource.Test(t, resource.TestCase{
403+
PreCheck: func() { tcacctest.AccPreCheck(t) },
404+
Providers: tcacctest.AccProviders,
405+
CheckDestroy: testAccCheckClbListenerDestroy,
406+
Steps: []resource.TestStep{
407+
{
408+
Config: testAccClbListener_udp,
409+
Check: resource.ComposeTestCheckFunc(
410+
testAccCheckClbListenerExists("tencentcloud_clb_listener.listener_basic_udp"),
411+
resource.TestCheckResourceAttrSet("tencentcloud_clb_listener.listener_basic_udp", "clb_id"),
412+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "protocol", "UDP"),
413+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "listener_name", "listener_basic_udp"),
414+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "session_expire_time", "30"),
415+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "port", "1"),
416+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "scheduler", "WRR"),
417+
),
418+
},
419+
{
420+
Config: testAccClbListener_udpUpdate,
421+
Check: resource.ComposeTestCheckFunc(
422+
testAccCheckClbListenerExists("tencentcloud_clb_listener.listener_basic_udp"),
423+
resource.TestCheckResourceAttrSet("tencentcloud_clb_listener.listener_basic_udp", "clb_id"),
424+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "protocol", "UDP"),
425+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "listener_name", "listener_basic_udp_update"),
426+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "session_expire_time", "30"),
427+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "port", "1"),
428+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "scheduler", "WRR"),
429+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic_udp", "health_check_type", "CUSTOM"),
430+
),
431+
},
432+
{
433+
ResourceName: "tencentcloud_clb_listener.listener_basic_udp",
434+
ImportState: true,
435+
ImportStateVerify: true,
436+
},
437+
},
438+
})
439+
}
400440
func testAccCheckClbListenerDestroy(s *terraform.State) error {
401441
logId := tccommon.GetLogId(tccommon.ContextNil)
402442
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
@@ -471,7 +511,39 @@ resource "tencentcloud_clb_listener" "listener_basic" {
471511
target_type = "TARGETGROUP"
472512
}
473513
`
514+
const testAccClbListener_udp = `
515+
resource "tencentcloud_clb_instance" "clb_basic_udp" {
516+
network_type = "OPEN"
517+
clb_name = "tf-clb-listener-basic"
518+
}
519+
520+
resource "tencentcloud_clb_listener" "listener_basic_udp" {
521+
clb_id = tencentcloud_clb_instance.clb_basic_udp.id
522+
port = 1
523+
protocol = "UDP"
524+
listener_name = "listener_basic_udp"
525+
session_expire_time = 30
526+
scheduler = "WRR"
527+
target_type = "TARGETGROUP"
528+
}
529+
`
530+
const testAccClbListener_udpUpdate = `
531+
resource "tencentcloud_clb_instance" "clb_basic_udp" {
532+
network_type = "OPEN"
533+
clb_name = "tf-clb-listener-basic"
534+
}
474535
536+
resource "tencentcloud_clb_listener" "listener_basic_udp" {
537+
clb_id = tencentcloud_clb_instance.clb_basic_udp.id
538+
port = 1
539+
protocol = "UDP"
540+
listener_name = "listener_basic_udp_update"
541+
session_expire_time = 30
542+
scheduler = "WRR"
543+
target_type = "TARGETGROUP"
544+
health_check_type = "CUSTOM"
545+
}
546+
`
475547
const testAccClbListener_portRange = `
476548
resource "tencentcloud_clb_instance" "clb_basic" {
477549
network_type = "OPEN"

tencentcloud/services/clb/service_tencentcloud_clb.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,29 +877,29 @@ func checkHealthCheckPara(ctx context.Context, d *schema.ResourceData, protocol
877877
healthCheck.HttpVersion = helper.String(v.(string))
878878
}
879879
if v, ok := d.GetOk("health_check_context_type"); ok {
880-
if !(protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_CUSTOM) {
880+
if !((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP) && checkType == HEALTH_CHECK_TYPE_CUSTOM) {
881881
healthSetFlag = false
882-
errRet = fmt.Errorf("health_check_context_type can only be set with protocol CUSTOM of TCP")
882+
errRet = fmt.Errorf("health_check_context_type can only be set with protocol CUSTOM of TCP/UDP")
883883
errRet = errors.WithStack(errRet)
884884
return
885885
}
886886
healthSetFlag = true
887887
healthCheck.ContextType = helper.String(v.(string))
888888
}
889889
if v, ok := d.GetOk("health_check_send_context"); ok {
890-
if !(protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_CUSTOM) {
890+
if !((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP) && checkType == HEALTH_CHECK_TYPE_CUSTOM) {
891891
healthSetFlag = false
892-
errRet = fmt.Errorf("health_check_send_context can only be set with protocol CUSTOM of TCP")
892+
errRet = fmt.Errorf("health_check_send_context can only be set with protocol CUSTOM of TCP/UDP")
893893
errRet = errors.WithStack(errRet)
894894
return
895895
}
896896
healthSetFlag = true
897897
healthCheck.SendContext = helper.String(v.(string))
898898
}
899899
if v, ok := d.GetOk("health_check_recv_context"); ok {
900-
if !(protocol == CLB_LISTENER_PROTOCOL_TCP && checkType == HEALTH_CHECK_TYPE_CUSTOM) {
900+
if !((protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCP) && checkType == HEALTH_CHECK_TYPE_CUSTOM) {
901901
healthSetFlag = false
902-
errRet = fmt.Errorf("health_check_recv_context can only be set with protocol CUSTOM of TCP")
902+
errRet = fmt.Errorf("health_check_recv_context can only be set with protocol CUSTOM of TCP/UDP")
903903
errRet = errors.WithStack(errRet)
904904
return
905905
}

0 commit comments

Comments
 (0)