Skip to content

Commit d46072c

Browse files
author
ttomzhou
committed
tencentcloud_clb_listener support HTTP health check for TCP listener
1 parent eb56eef commit d46072c

File tree

10 files changed

+609
-47
lines changed

10 files changed

+609
-47
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
## 1.47.1 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
5+
* Resource: `tencentcloud_clb_listener` support configure HTTP health check for TCP listener([#539](https://github.com/tencentcloudstack/terraform-provider-tencentcloud/issues/539)).
6+
* Data Source: `tencentcloud_clb_listeners` support getting HTTP health check config for TCP listener.
7+
28
## 1.47.0 (November 13, 2020)
39

410
ENHANCEMENTS:

examples/tencentcloud-clb/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ resource "tencentcloud_clb_listener" "listener_tcp" {
4848
health_check_unhealth_num = 2
4949
session_expire_time = 30
5050
scheduler = "WRR"
51+
health_check_port = 200
52+
health_check_type = "HTTP"
53+
health_check_http_code = 2
54+
health_check_http_version = "HTTP/1.0"
55+
health_check_http_method = "GET"
5156
}
5257

5358
resource "tencentcloud_clb_attachment" "attachment_tcp" {

tencentcloud/data_source_tc_clb_listeners.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,56 @@ func dataSourceTencentCloudClbListeners() *schema.Resource {
112112
Computed: true,
113113
Description: "Unhealthy threshold of health check, and the default is 3. If a success result is returned for the health check three consecutive times, the CVM is identified as unhealthy. The value range is 2-10. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in tencentcloud_clb_listener_rule.",
114114
},
115+
"health_check_type": {
116+
Type: schema.TypeString,
117+
Computed: true,
118+
Description: "Protocol used for health check.",
119+
},
120+
"health_check_port": {
121+
Type: schema.TypeInt,
122+
Computed: true,
123+
Description: "The health check port is the port of the backend service.",
124+
},
125+
"health_check_http_version": {
126+
Type: schema.TypeString,
127+
Computed: true,
128+
Description: "The HTTP version of the backend service.",
129+
},
130+
"health_check_http_code": {
131+
Type: schema.TypeInt,
132+
Computed: true,
133+
Description: "HTTP health check code of TCP listener.",
134+
},
135+
"health_check_http_path": {
136+
Type: schema.TypeString,
137+
Computed: true,
138+
Description: "HTTP health check path of TCP listener.",
139+
},
140+
"health_check_http_domain": {
141+
Type: schema.TypeString,
142+
Computed: true,
143+
Description: "HTTP health check domain of TCP listener.",
144+
},
145+
"health_check_http_method": {
146+
Type: schema.TypeString,
147+
Computed: true,
148+
Description: "HTTP health check method of TCP listener.",
149+
},
150+
"health_check_context_type": {
151+
Type: schema.TypeString,
152+
Computed: true,
153+
Description: "Health check protocol.",
154+
},
155+
"health_check_send_context": {
156+
Type: schema.TypeString,
157+
Computed: true,
158+
Description: "It represents the content of the request sent by the health check.",
159+
},
160+
"health_check_recv_context": {
161+
Type: schema.TypeString,
162+
Computed: true,
163+
Description: "It represents the result returned by the health check.",
164+
},
115165
"certificate_ssl_mode": {
116166
Type: schema.TypeString,
117167
Computed: true,
@@ -223,6 +273,16 @@ func dataSourceTencentCloudClbListenersRead(d *schema.ResourceData, meta interfa
223273
mapping["health_check_interval_time"] = *listener.HealthCheck.IntervalTime
224274
mapping["health_check_health_num"] = *listener.HealthCheck.HealthNum
225275
mapping["health_check_unhealth_num"] = *listener.HealthCheck.UnHealthNum
276+
mapping["health_check_http_code"] = listener.HealthCheck.HttpCode
277+
mapping["health_check_http_path"] = listener.HealthCheck.HttpCheckPath
278+
mapping["health_check_http_domain"] = listener.HealthCheck.HttpCheckDomain
279+
mapping["health_check_http_method"] = listener.HealthCheck.HttpCheckMethod
280+
mapping["health_check_http_version"] = listener.HealthCheck.HttpVersion
281+
mapping["health_check_context_type"] = listener.HealthCheck.ContextType
282+
mapping["health_check_send_context"] = listener.HealthCheck.SendContext
283+
mapping["health_check_recv_context"] = listener.HealthCheck.RecvContext
284+
mapping["health_check_type"] = listener.HealthCheck.CheckType
285+
mapping["health_check_port"] = listener.HealthCheck.CheckPort
226286
}
227287
if listener.Certificate != nil {
228288
mapping["certificate_ssl_mode"] = *listener.Certificate.SSLMode

tencentcloud/data_source_tc_clb_listeners_test.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ func TestAccTencentCloudClbListenersDataSource(t *testing.T) {
2626
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.protocol", "TCP"),
2727
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.session_expire_time", "30"),
2828
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.scheduler", "WRR"),
29+
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_type", "HTTP"),
30+
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_port", "0"),
31+
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_code", "16"),
32+
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_path", "/"),
33+
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_domain", "www.tencent.com"),
34+
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_method", "HEAD"),
35+
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_version", "HTTP/1.1"),
2936
),
3037
},
3138
},
@@ -34,21 +41,27 @@ func TestAccTencentCloudClbListenersDataSource(t *testing.T) {
3441

3542
const testAccClbListenersDataSource = `
3643
resource "tencentcloud_clb_instance" "clb" {
37-
network_type = "OPEN"
38-
clb_name = "tf-clb-listeners"
44+
network_type = "OPEN"
45+
clb_name = "tf-clb-listeners"
3946
}
4047
4148
resource "tencentcloud_clb_listener" "listener" {
42-
clb_id = tencentcloud_clb_instance.clb.id
43-
port = 1
44-
protocol = "TCP"
45-
listener_name = "mylistener1234"
46-
session_expire_time = 30
47-
scheduler = "WRR"
49+
clb_id = tencentcloud_clb_instance.clb.id
50+
port = 1
51+
protocol = "TCP"
52+
listener_name = "mylistener1234"
53+
session_expire_time = 30
54+
scheduler = "WRR"
55+
health_check_type = "HTTP"
56+
health_check_http_domain = "www.tencent.com"
57+
health_check_http_code = 16
58+
health_check_http_version = "HTTP/1.1"
59+
health_check_http_method = "HEAD"
60+
health_check_http_path = "/"
4861
}
4962
5063
data "tencentcloud_clb_listeners" "listeners" {
51-
clb_id = tencentcloud_clb_instance.clb.id
52-
listener_id = tencentcloud_clb_listener.listener.listener_id
64+
clb_id = tencentcloud_clb_instance.clb.id
65+
listener_id = tencentcloud_clb_listener.listener.listener_id
5366
}
5467
`

tencentcloud/extension_clb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ var HTTP_VERSION = []string{
6161
const (
6262
HEALTH_CHECK_TYPE_CUSTOM = "CUSTOM"
6363
HEALTH_CHECK_TYPE_TCP = "TCP"
64-
HEALTH_CHECK_TYPE_UDP = "UDP"
64+
HEALTH_CHECK_TYPE_HTTP = "HTTP"
6565
)
6666

6767
var HEALTH_CHECK_TYPE = []string{
6868
HEALTH_CHECK_TYPE_CUSTOM,
6969
HEALTH_CHECK_TYPE_TCP,
70-
HEALTH_CHECK_TYPE_UDP,
70+
HEALTH_CHECK_TYPE_HTTP,
7171
}
7272

7373
const (

tencentcloud/resource_tc_clb_listener.go

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ resource "tencentcloud_clb_listener" "TCP_listener" {
2929
health_check_unhealth_num = 3
3030
session_expire_time = 30
3131
scheduler = "WRR"
32+
health_check_port = 200
33+
health_check_type = "HTTP"
34+
health_check_http_code = 2
35+
health_check_http_version = "HTTP/1.0"
36+
health_check_http_method = "GET"
3237
}
3338
```
3439
@@ -159,7 +164,89 @@ func resourceTencentCloudClbListener() *schema.Resource {
159164
Optional: true,
160165
Computed: true,
161166
ValidateFunc: validateIntegerInRange(2, 10),
162-
Description: "Unhealthy threshold of health check, and the default is 3. If a success result is returned for the health check 3 consecutive times, the CVM is identified as unhealthy. The value range is 2-10. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in tencentcloud_clb_listener_rule.",
167+
Description: "Unhealthy threshold of health check, and the default is 3. " +
168+
"If a success result is returned for the health check 3 consecutive times, " +
169+
"the CVM is identified as unhealthy. The value range is 2-10. " +
170+
"NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, " +
171+
"HTTP/HTTPS listener needs to be configured in tencentcloud_clb_listener_rule.",
172+
},
173+
"health_check_type": {
174+
Type: schema.TypeString,
175+
Optional: true,
176+
Computed: true,
177+
ValidateFunc: validateAllowedStringValue(HEALTH_CHECK_TYPE),
178+
Description: "Protocol used for health check. Valid values: `CUSTOM`, `TCP`, `HTTP`.",
179+
},
180+
"health_check_port": {
181+
Type: schema.TypeInt,
182+
Optional: true,
183+
ValidateFunc: validateIntegerInRange(1, 65535),
184+
Description: "The health check port is the port of the backend service by default. " +
185+
"Unless you want to specify a specific port, it is recommended to leave it blank. " +
186+
"Only applicable to TCP/UDP listener.",
187+
},
188+
"health_check_http_version": {
189+
Type: schema.TypeString,
190+
Optional: true,
191+
ValidateFunc: validateAllowedStringValue(HTTP_VERSION),
192+
Description: "The HTTP version of the backend service. When the value of `health_check_type` of " +
193+
"the health check protocol is `HTTP`, this field is required. " +
194+
"Valid values: `HTTP/1.0`, `HTTP/1.1`.",
195+
},
196+
"health_check_http_code": {
197+
Type: schema.TypeInt,
198+
Optional: true,
199+
ValidateFunc: validateAllowedIntValue([]int{1, 2, 4, 8, 16}),
200+
Description: "HTTP health check code of TCP listener. When the value of `health_check_type` of " +
201+
"the health check protocol is `HTTP`, this field is required. Valid values: 1, 2, 4, 8, 16. " +
202+
"1 means http_1xx, 2 means http_2xx, 4 means http_3xx, 8 means http_4xx, 16 means http_5xx.",
203+
},
204+
"health_check_http_path": {
205+
Type: schema.TypeString,
206+
Optional: true,
207+
Description: "HTTP health check path of TCP listener.",
208+
},
209+
"health_check_http_domain": {
210+
Type: schema.TypeString,
211+
Optional: true,
212+
Description: "HTTP health check domain of TCP listener.",
213+
},
214+
"health_check_http_method": {
215+
Type: schema.TypeString,
216+
Optional: true,
217+
Computed: true,
218+
ValidateFunc: validateAllowedStringValue(CLB_HTTP_METHOD),
219+
Description: "HTTP health check method of TCP listener. Valid values: `HEAD`, `GET`.",
220+
},
221+
"health_check_context_type": {
222+
Type: schema.TypeString,
223+
Optional: true,
224+
ValidateFunc: validateAllowedStringValue(CONTEX_TYPE),
225+
Description: "Health check protocol. When the value of `health_check_type` of the health check protocol is `CUSTOM`, " +
226+
"this field is required, which represents the input format of the health check. " +
227+
"Valid values: `HEX`, `TEXT`.",
228+
},
229+
"health_check_send_context": {
230+
Type: schema.TypeString,
231+
Optional: true,
232+
ValidateFunc: validateStringLengthInRange(0, 500),
233+
Description: "It represents the content of the request sent by the health check. " +
234+
"When the value of `health_check_type` of the health check protocol is `CUSTOM`, " +
235+
"this field is required. Only visible ASCII characters are allowed and the maximum length is 500. " +
236+
"When `health_check_context_type` value is `HEX`, " +
237+
"the characters of SendContext and RecvContext can only be selected in `0123456789ABCDEF` " +
238+
"and the length must be even digits.",
239+
},
240+
"health_check_recv_context": {
241+
Type: schema.TypeString,
242+
Optional: true,
243+
ValidateFunc: validateStringLengthInRange(0, 500),
244+
Description: "It represents the result returned by the health check. " +
245+
"When the value of `health_check_type` of the health check protocol is `CUSTOM`, " +
246+
"this field is required. Only ASCII visible characters are allowed and the maximum length is 500. " +
247+
"When `health_check_context_type` value is `HEX`, " +
248+
"the characters of SendContext and RecvContext can only be selected in `0123456789ABCDEF` " +
249+
"and the length must be even digits.",
163250
},
164251
"certificate_ssl_mode": {
165252
Type: schema.TypeString,
@@ -326,7 +413,7 @@ func resourceTencentCloudClbListenerRead(d *schema.ResourceData, meta interface{
326413
clbId := d.Get("clb_id").(string)
327414

328415
if itemLength == 1 && clbId == "" {
329-
return fmt.Errorf("The old style listenerId %s does not support import, please use clbId#listenerId style", resourceId)
416+
return fmt.Errorf("the old style listenerId %s does not support import, please use clbId#listenerId style", resourceId)
330417
} else if itemLength == 2 && clbId == "" {
331418
listenerId = items[1]
332419
clbId = items[0]
@@ -368,15 +455,25 @@ func resourceTencentCloudClbListenerRead(d *schema.ResourceData, meta interface{
368455

369456
//health check
370457
if instance.HealthCheck != nil {
371-
health_check_switch := false
458+
healthCheckSwitch := false
372459
if *instance.HealthCheck.HealthSwitch == int64(1) {
373-
health_check_switch = true
460+
healthCheckSwitch = true
374461
}
375-
_ = d.Set("health_check_switch", health_check_switch)
462+
_ = d.Set("health_check_switch", healthCheckSwitch)
376463
_ = d.Set("health_check_interval_time", instance.HealthCheck.IntervalTime)
377464
_ = d.Set("health_check_time_out", instance.HealthCheck.TimeOut)
378465
_ = d.Set("health_check_health_num", instance.HealthCheck.HealthNum)
379466
_ = d.Set("health_check_unhealth_num", instance.HealthCheck.UnHealthNum)
467+
_ = d.Set("health_check_port", instance.HealthCheck.CheckPort)
468+
_ = d.Set("health_check_type", instance.HealthCheck.CheckType)
469+
_ = d.Set("health_check_http_code", instance.HealthCheck.HttpCode)
470+
_ = d.Set("health_check_http_path", instance.HealthCheck.HttpCheckPath)
471+
_ = d.Set("health_check_http_domain", instance.HealthCheck.HttpCheckDomain)
472+
_ = d.Set("health_check_http_method", instance.HealthCheck.HttpCheckMethod)
473+
_ = d.Set("health_check_http_version", instance.HealthCheck.HttpVersion)
474+
_ = d.Set("health_check_context_type", instance.HealthCheck.ContextType)
475+
_ = d.Set("health_check_send_context", instance.HealthCheck.SendContext)
476+
_ = d.Set("health_check_recv_context", instance.HealthCheck.RecvContext)
380477
}
381478

382479
if instance.Certificate != nil {
@@ -483,7 +580,7 @@ func resourceTencentCloudClbListenerUpdate(d *schema.ResourceData, meta interfac
483580
}
484581
}
485582

486-
return nil
583+
return resourceTencentCloudClbListenerRead(d, meta)
487584
}
488585

489586
func resourceTencentCloudClbListenerDelete(d *schema.ResourceData, meta interface{}) error {

0 commit comments

Comments
 (0)