@@ -67,14 +67,14 @@ func ResourceTencentCloudGaapLayer4Listener() *schema.Resource {
67
67
Type : schema .TypeBool ,
68
68
Optional : true ,
69
69
Default : false ,
70
- Description : "Indicates whether health check is enable, default value is `false`. NOTES: Only supports listeners of `TCP` protocol. " ,
70
+ Description : "Indicates whether health check is enable, default value is `false`." ,
71
71
},
72
72
"interval" : {
73
73
Type : schema .TypeInt ,
74
74
Optional : true ,
75
75
Default : 5 ,
76
76
ValidateFunc : tccommon .ValidateIntegerInRange (5 , 300 ),
77
- Description : "Interval of the health check, default value is 5s. NOTES: Only supports listeners of `TCP` protocol. " ,
77
+ Description : "Interval of the health check, default value is 5s." ,
78
78
},
79
79
"connect_timeout" : {
80
80
Type : schema .TypeInt ,
@@ -83,6 +83,52 @@ func ResourceTencentCloudGaapLayer4Listener() *schema.Resource {
83
83
ValidateFunc : tccommon .ValidateIntegerInRange (2 , 60 ),
84
84
Description : "Timeout of the health check response, should less than interval, default value is 2s. NOTES: Only supports listeners of `TCP` protocol and require less than `interval`." ,
85
85
},
86
+ "healthy_threshold" : {
87
+ Type : schema .TypeInt ,
88
+ Optional : true ,
89
+ Default : 1 ,
90
+ ValidateFunc : tccommon .ValidateIntegerInRange (1 , 10 ),
91
+ Description : "Health threshold, which indicates how many consecutive inspections are successful, the source station is determined to be healthy. Range from 1 to 10. Default value is 1." ,
92
+ },
93
+ "unhealthy_threshold" : {
94
+ Type : schema .TypeInt ,
95
+ Optional : true ,
96
+ Default : 1 ,
97
+ ValidateFunc : tccommon .ValidateIntegerInRange (1 , 10 ),
98
+ Description : "Unhealthy threshold, which indicates how many consecutive check failures the source station is considered unhealthy. Range from 1 to 10. Default value is 1." ,
99
+ },
100
+ "check_type" : {
101
+ Type : schema .TypeString ,
102
+ Optional : true ,
103
+ Computed : true ,
104
+ ValidateFunc : tccommon .ValidateAllowedStringValue ([]string {"PORT" , "PING" }),
105
+ Description : "UDP origin server health type. PORT means check port, and PING means PING." ,
106
+ },
107
+ "check_port" : {
108
+ Type : schema .TypeInt ,
109
+ Optional : true ,
110
+ Computed : true ,
111
+ Description : "UDP origin station health check probe port." ,
112
+ },
113
+ "context_type" : {
114
+ Type : schema .TypeString ,
115
+ Optional : true ,
116
+ Computed : true ,
117
+ ValidateFunc : tccommon .ValidateAllowedStringValue ([]string {"TEXT" }),
118
+ Description : "UDP source station health check port probe message type: TEXT represents text. Only used when the health check type is PORT." ,
119
+ },
120
+ "send_context" : {
121
+ Type : schema .TypeString ,
122
+ Optional : true ,
123
+ Computed : true ,
124
+ Description : "UDP source server health check port detection sends messages. Only used when health check type is PORT." ,
125
+ },
126
+ "recv_context" : {
127
+ Type : schema .TypeString ,
128
+ Optional : true ,
129
+ Computed : true ,
130
+ Description : "UDP source server health check port detects received messages. Only used when the health check type is PORT." ,
131
+ },
86
132
"client_ip_method" : {
87
133
Type : schema .TypeInt ,
88
134
Optional : true ,
@@ -164,12 +210,10 @@ func resourceTencentCloudGaapLayer4ListenerCreate(d *schema.ResourceData, m inte
164
210
proxyId := d .Get ("proxy_id" ).(string )
165
211
healthCheck := d .Get ("health_check" ).(bool )
166
212
167
- if protocol == "UDP" && healthCheck {
168
- return errors .New ("UDP listener can't use health check" )
169
- }
170
-
171
213
interval := d .Get ("interval" ).(int )
172
214
connectTimeout := d .Get ("connect_timeout" ).(int )
215
+ healthyThreshold := d .Get ("healthy_threshold" ).(int )
216
+ unhealthyThreshold := d .Get ("unhealthy_threshold" ).(int )
173
217
174
218
// only check for TCP listener
175
219
if protocol == "TCP" && connectTimeout >= interval {
@@ -206,13 +250,33 @@ func resourceTencentCloudGaapLayer4ListenerCreate(d *schema.ResourceData, m inte
206
250
207
251
switch protocol {
208
252
case "TCP" :
209
- id , err = service .CreateTCPListener (ctx , name , scheduler , realserverType , proxyId , port , interval , connectTimeout , clientIPMethod , healthCheck )
253
+ id , err = service .CreateTCPListener (ctx , name , scheduler , realserverType , proxyId , port , interval , connectTimeout , clientIPMethod , healthyThreshold , unhealthyThreshold , healthCheck )
210
254
if err != nil {
211
255
return err
212
256
}
213
257
214
258
case "UDP" :
215
- id , err = service .CreateUDPListener (ctx , name , scheduler , realserverType , proxyId , port )
259
+ optionalParams := make (map [string ]interface {})
260
+ if v , ok := d .GetOk ("check_type" ); ok {
261
+ optionalParams ["check_type" ] = v .(string )
262
+ } else {
263
+ if healthCheck {
264
+ return errors .New ("Must set check_type when enable health_check." )
265
+ }
266
+ }
267
+ if v , ok := d .GetOk ("check_port" ); ok {
268
+ optionalParams ["check_port" ] = v .(int )
269
+ }
270
+ if v , ok := d .GetOk ("context_type" ); ok {
271
+ optionalParams ["context_type" ] = v .(string )
272
+ }
273
+ if v , ok := d .GetOk ("send_context" ); ok {
274
+ optionalParams ["send_context" ] = v .(string )
275
+ }
276
+ if v , ok := d .GetOk ("recv_context" ); ok {
277
+ optionalParams ["recv_context" ] = v .(string )
278
+ }
279
+ id , err = service .CreateUDPListener (ctx , name , scheduler , realserverType , proxyId , port , interval , connectTimeout , healthyThreshold , unhealthyThreshold , healthCheck , optionalParams )
216
280
if err != nil {
217
281
return err
218
282
}
@@ -239,19 +303,26 @@ func resourceTencentCloudGaapLayer4ListenerRead(d *schema.ResourceData, m interf
239
303
id := d .Id ()
240
304
241
305
var (
242
- protocol string
243
- name * string
244
- port * uint64
245
- scheduler * string
246
- realServerType * string
247
- healthCheck * bool
248
- interval * uint64
249
- connectTimeout * uint64
250
- status * uint64
251
- createTime string
252
- realservers []map [string ]interface {}
253
- clientIpMethod * uint64
254
- proxyId * string
306
+ protocol string
307
+ name * string
308
+ port * uint64
309
+ scheduler * string
310
+ realServerType * string
311
+ healthCheck * bool
312
+ interval * uint64
313
+ connectTimeout * uint64
314
+ status * uint64
315
+ createTime string
316
+ realservers []map [string ]interface {}
317
+ clientIpMethod * uint64
318
+ proxyId * string
319
+ healthyThreshold * uint64
320
+ unhealthyThreshold * uint64
321
+ checkType * string
322
+ checkPort * int64
323
+ contextType * string
324
+ sendContext * string
325
+ recvContext * string
255
326
)
256
327
257
328
service := GaapService {client : m .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
@@ -285,6 +356,8 @@ func resourceTencentCloudGaapLayer4ListenerRead(d *schema.ResourceData, m interf
285
356
286
357
interval = listener .DelayLoop
287
358
connectTimeout = listener .ConnectTimeout
359
+ healthyThreshold = listener .HealthyThreshold
360
+ unhealthyThreshold = listener .UnhealthyThreshold
288
361
289
362
if len (listener .RealServerSet ) > 0 {
290
363
realservers = make ([]map [string ]interface {}, 0 , len (listener .RealServerSet ))
@@ -316,11 +389,16 @@ func resourceTencentCloudGaapLayer4ListenerRead(d *schema.ResourceData, m interf
316
389
realServerType = listener .RealServerType
317
390
proxyId = listener .ProxyId
318
391
319
- healthCheck = helper .Bool (false )
320
- connectTimeout = helper .IntUint64 (2 )
321
- interval = helper .IntUint64 (5 )
322
- clientIpMethod = helper .IntUint64 (0 )
323
-
392
+ healthCheck = helper .Bool (* listener .HealthCheck == 1 )
393
+ connectTimeout = listener .ConnectTimeout
394
+ interval = listener .DelayLoop
395
+ healthyThreshold = listener .HealthyThreshold
396
+ unhealthyThreshold = listener .UnhealthyThreshold
397
+ checkType = listener .CheckType
398
+ checkPort = listener .CheckPort
399
+ contextType = listener .ContextType
400
+ sendContext = listener .SendContext
401
+ recvContext = listener .RecvContext
324
402
if len (listener .RealServerSet ) > 0 {
325
403
realservers = make ([]map [string ]interface {}, 0 , len (listener .RealServerSet ))
326
404
for _ , rs := range listener .RealServerSet {
@@ -353,12 +431,22 @@ func resourceTencentCloudGaapLayer4ListenerRead(d *schema.ResourceData, m interf
353
431
_ = d .Set ("health_check" , healthCheck )
354
432
_ = d .Set ("interval" , interval )
355
433
_ = d .Set ("connect_timeout" , connectTimeout )
356
- _ = d .Set ("client_ip_method" , clientIpMethod )
357
434
_ = d .Set ("realserver_bind_set" , realservers )
358
435
_ = d .Set ("status" , status )
359
436
_ = d .Set ("create_time" , createTime )
360
437
_ = d .Set ("proxy_id" , proxyId )
361
-
438
+ _ = d .Set ("healthy_threshold" , healthyThreshold )
439
+ _ = d .Set ("unhealthy_threshold" , unhealthyThreshold )
440
+ if protocol == "TCP" {
441
+ _ = d .Set ("client_ip_method" , clientIpMethod )
442
+ }
443
+ if protocol == "UDP" {
444
+ _ = d .Set ("check_type" , checkType )
445
+ _ = d .Set ("check_port" , checkPort )
446
+ _ = d .Set ("context_type" , contextType )
447
+ _ = d .Set ("send_context" , sendContext )
448
+ _ = d .Set ("recv_context" , recvContext )
449
+ }
362
450
return nil
363
451
}
364
452
@@ -374,12 +462,14 @@ func resourceTencentCloudGaapLayer4ListenerUpdate(d *schema.ResourceData, m inte
374
462
protocol := d .Get ("protocol" ).(string )
375
463
proxyId := d .Get ("proxy_id" ).(string )
376
464
var (
377
- name * string
378
- scheduler * string
379
- healthCheck * bool
380
- interval int
381
- connectTimeout int
382
- attrChange []string
465
+ name * string
466
+ scheduler * string
467
+ healthCheck * bool
468
+ interval int
469
+ connectTimeout int
470
+ attrChange []string
471
+ healthyThreshold int
472
+ unhealthyThreshold int
383
473
)
384
474
385
475
service := GaapService {client : m .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
@@ -388,21 +478,18 @@ func resourceTencentCloudGaapLayer4ListenerUpdate(d *schema.ResourceData, m inte
388
478
389
479
if d .HasChange ("name" ) {
390
480
attrChange = append (attrChange , "name" )
391
- name = helper .String (d .Get ("name" ).(string ))
392
481
}
482
+ name = helper .String (d .Get ("name" ).(string ))
393
483
394
484
if d .HasChange ("scheduler" ) {
395
485
attrChange = append (attrChange , "scheduler" )
396
- scheduler = helper .String (d .Get ("scheduler" ).(string ))
397
486
}
487
+ scheduler = helper .String (d .Get ("scheduler" ).(string ))
398
488
399
489
if d .HasChange ("health_check" ) {
400
490
attrChange = append (attrChange , "health_check" )
401
- healthCheck = helper .Bool (d .Get ("health_check" ).(bool ))
402
- }
403
- if protocol == "UDP" && healthCheck != nil && * healthCheck {
404
- return errors .New ("UDP listener can't enable health check" )
405
491
}
492
+ healthCheck = helper .Bool (d .Get ("health_check" ).(bool ))
406
493
407
494
if d .HasChange ("interval" ) {
408
495
attrChange = append (attrChange , "interval" )
@@ -414,6 +501,47 @@ func resourceTencentCloudGaapLayer4ListenerUpdate(d *schema.ResourceData, m inte
414
501
}
415
502
connectTimeout = d .Get ("connect_timeout" ).(int )
416
503
504
+ if d .HasChange ("healthy_threshold" ) {
505
+ attrChange = append (attrChange , "healthy_threshold" )
506
+ }
507
+ healthyThreshold = d .Get ("healthy_threshold" ).(int )
508
+
509
+ if d .HasChange ("unhealthy_threshold" ) {
510
+ attrChange = append (attrChange , "unhealthy_threshold" )
511
+ }
512
+ unhealthyThreshold = d .Get ("unhealthy_threshold" ).(int )
513
+
514
+ optionalParams := make (map [string ]interface {})
515
+ if d .HasChange ("check_type" ) {
516
+ attrChange = append (attrChange , "check_type" )
517
+ }
518
+ if d .HasChange ("check_port" ) {
519
+ attrChange = append (attrChange , "check_port" )
520
+ }
521
+ if d .HasChange ("context_type" ) {
522
+ attrChange = append (attrChange , "context_type" )
523
+ }
524
+ if d .HasChange ("send_context" ) {
525
+ attrChange = append (attrChange , "send_context" )
526
+ }
527
+ if d .HasChange ("recv_context" ) {
528
+ attrChange = append (attrChange , "recv_context" )
529
+ }
530
+ if v , ok := d .GetOk ("check_type" ); ok {
531
+ optionalParams ["check_type" ] = v .(string )
532
+ }
533
+ if v , ok := d .GetOk ("check_port" ); ok {
534
+ optionalParams ["check_port" ] = v .(int )
535
+ }
536
+ if v , ok := d .GetOk ("context_type" ); ok {
537
+ optionalParams ["context_type" ] = v .(string )
538
+ }
539
+ if v , ok := d .GetOk ("send_context" ); ok {
540
+ optionalParams ["send_context" ] = v .(string )
541
+ }
542
+ if v , ok := d .GetOk ("recv_context" ); ok {
543
+ optionalParams ["recv_context" ] = v .(string )
544
+ }
417
545
// only check for TCP listener
418
546
if protocol == "TCP" && connectTimeout >= interval {
419
547
return errors .New ("connect_timeout must be less than interval" )
@@ -422,12 +550,12 @@ func resourceTencentCloudGaapLayer4ListenerUpdate(d *schema.ResourceData, m inte
422
550
if len (attrChange ) > 0 {
423
551
switch protocol {
424
552
case "TCP" :
425
- if err := service .ModifyTCPListenerAttribute (ctx , proxyId , id , name , scheduler , healthCheck , interval , connectTimeout ); err != nil {
553
+ if err := service .ModifyTCPListenerAttribute (ctx , proxyId , id , name , scheduler , healthCheck , interval , connectTimeout , healthyThreshold , unhealthyThreshold ); err != nil {
426
554
return err
427
555
}
428
556
429
557
case "UDP" :
430
- if err := service .ModifyUDPListenerAttribute (ctx , proxyId , id , name , scheduler ); err != nil {
558
+ if err := service .ModifyUDPListenerAttribute (ctx , proxyId , id , name , scheduler , connectTimeout , interval , healthyThreshold , unhealthyThreshold , healthCheck , optionalParams ); err != nil {
431
559
return err
432
560
}
433
561
}
0 commit comments