Skip to content

Commit 8b47ee7

Browse files
authored
Merge pull request #551 from ttomzhou/master
tencentcloud_clb_listener support HTTP health check for TCP listener
2 parents b0f8cdd + 0f7dbfd commit 8b47ee7

17 files changed

+845
-102
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
## 1.47.1 (Unreleased)
22

33
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)).
46
* Resource: `tencentcloud_clb_listener` add computed argument `target_type`.
7+
* Data Source: `tencentcloud_clb_listeners` support getting HTTP health check config for TCP listener.
58

69
DEPRECATED:
710
* Resource: `tencentcloud_clb_target_group_attachment`: optional argument `targrt_group_id` is no longer supported, replace by `target_group_id`.
811

12+
913
## 1.47.0 (November 13, 2020)
1014

1115
ENHANCEMENTS:

examples/tencentcloud-clb/main.tf

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ resource "tencentcloud_security_group" "foo" {
33
}
44

55
resource "tencentcloud_vpc" "foo" {
6-
name = "example"
6+
name = "ci-test-eni-vpc"
77
cidr_block = "10.0.0.0/16"
88
}
99

1010
resource "tencentcloud_subnet" "foo" {
11-
name = "example"
1211
availability_zone = var.availability_zone
12+
name = "ci-test-eni-subnet"
1313
vpc_id = tencentcloud_vpc.foo.id
14-
cidr_block = "10.0.0.0/24"
14+
cidr_block = "10.0.0.0/16"
1515
is_multicast = false
1616
}
1717

@@ -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" {
@@ -67,7 +72,7 @@ resource "tencentcloud_clb_listener" "listener_https" {
6772
port = 443
6873
protocol = "HTTPS"
6974
certificate_ssl_mode = "UNIDIRECTIONAL"
70-
certificate_id = "VfqO4zkB"
75+
certificate_id = "f8k7ke6a"
7176
}
7277

7378
resource "tencentcloud_clb_listener_rule" "rule_https" {
@@ -127,8 +132,8 @@ resource "tencentcloud_clb_redirection" "redirection_http" {
127132
clb_id = tencentcloud_clb_instance.example.id
128133
source_listener_id = tencentcloud_clb_listener.listener_http_src.listener_id
129134
target_listener_id = tencentcloud_clb_listener.listener_http_dst.listener_id
130-
source_rule_id = tencentcloud_clb_listener_rule.rule_http_src.listener_id
131-
target_rule_id = tencentcloud_clb_listener_rule.rule_http_dst.listener_id
135+
source_rule_id = tencentcloud_clb_listener_rule.rule_http_src.rule_id
136+
target_rule_id = tencentcloud_clb_listener_rule.rule_http_dst.rule_id
132137
}
133138

134139
resource "tencentcloud_clb_instance" "clb_basic" {
@@ -157,18 +162,74 @@ resource "tencentcloud_clb_target_group" "test"{
157162
target_group_name = "test-target-keep-1"
158163
}
159164

160-
resource "tencentcloud_clb_target_group_instance_attachment" "test"{
161-
target_group_id = tencentcloud_clb_target_group.test.id
162-
bind_ip = "172.16.48.18"
163-
port = 222
164-
weight = 3
165+
data "tencentcloud_images" "my_favorite_image" {
166+
image_type = ["PUBLIC_IMAGE"]
167+
os_name = "centos"
168+
}
169+
170+
data "tencentcloud_instance_types" "my_favorite_instance_types" {
171+
filter {
172+
name = "instance-family"
173+
values = ["S3"]
174+
}
175+
176+
cpu_core_count = 1
177+
memory_size = 1
178+
}
179+
180+
data "tencentcloud_availability_zones" "default" {
181+
}
182+
183+
resource "tencentcloud_vpc" "app" {
184+
cidr_block = "10.0.0.0/16"
185+
name = "awesome_app_vpc"
186+
}
187+
188+
resource "tencentcloud_subnet" "app" {
189+
vpc_id = tencentcloud_vpc.app.id
190+
availability_zone = data.tencentcloud_availability_zones.default.zones.0.name
191+
name = "awesome_app_subnet"
192+
cidr_block = "10.0.1.0/24"
165193
}
166194

167-
resource "tencentcloud_clb_target_group_attachment" "group" {
168-
clb_id = tencentcloud_clb_instance.clb_basic.id
169-
listener_id = tencentcloud_clb_listener.listener_basic.listener_id
170-
rule_id = tencentcloud_clb_listener_rule.rule_basic.rule_id
171-
targrt_group_id = tencentcloud_clb_target_group.test.id
195+
resource "tencentcloud_instance" "my_awesome_app" {
196+
instance_name = "awesome_app"
197+
availability_zone = data.tencentcloud_availability_zones.default.zones.0.name
198+
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
199+
instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type
200+
system_disk_type = "CLOUD_PREMIUM"
201+
system_disk_size = 50
202+
hostname = "user"
203+
project_id = 0
204+
vpc_id = tencentcloud_vpc.app.id
205+
subnet_id = tencentcloud_subnet.app.id
206+
internet_max_bandwidth_out = 20
207+
208+
data_disks {
209+
data_disk_type = "CLOUD_PREMIUM"
210+
data_disk_size = 50
211+
encrypt = false
212+
}
213+
214+
tags = {
215+
tagKey = "tagValue"
216+
}
217+
}
218+
219+
data "tencentcloud_instances" "foo" {
220+
instance_id = tencentcloud_instance.my_awesome_app.id
221+
}
222+
223+
resource "tencentcloud_clb_target_group" "test_instance_attachment"{
224+
target_group_name = "test"
225+
vpc_id = tencentcloud_vpc.app.id
226+
}
227+
228+
resource "tencentcloud_clb_target_group_instance_attachment" "test"{
229+
target_group_id = tencentcloud_clb_target_group.test_instance_attachment.id
230+
bind_ip = data.tencentcloud_instances.foo.instance_list[0].private_ip
231+
port = 88
232+
weight = 3
172233
}
173234

174235
data "tencentcloud_clb_target_groups" "target_group_info_id" {

tencentcloud/data_source_tc_clb_attachments_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ resource "tencentcloud_clb_listener" "foo" {
5151
5252
resource "tencentcloud_clb_attachment" "foo" {
5353
clb_id = tencentcloud_clb_instance.foo.id
54-
listener_id = tencentcloud_clb_listener.foo.id
54+
listener_id = tencentcloud_clb_listener.foo.listener_id
5555
5656
targets {
5757
instance_id = tencentcloud_instance.default.id

tencentcloud/data_source_tc_clb_listeners.go

Lines changed: 73 additions & 15 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,
@@ -195,13 +245,13 @@ func dataSourceTencentCloudClbListenersRead(d *schema.ResourceData, meta interfa
195245
for _, listener := range listeners {
196246
mapping := map[string]interface{}{
197247
"clb_id": clbId,
198-
"listener_id": *listener.ListenerId,
199-
"listener_name": *listener.ListenerName,
200-
"protocol": *listener.Protocol,
201-
"port": *listener.Port,
248+
"listener_id": listener.ListenerId,
249+
"listener_name": listener.ListenerName,
250+
"protocol": listener.Protocol,
251+
"port": listener.Port,
202252
}
203253
if listener.SessionExpireTime != nil {
204-
mapping["session_expire_time"] = *listener.SessionExpireTime
254+
mapping["session_expire_time"] = listener.SessionExpireTime
205255
}
206256
if listener.SniSwitch != nil {
207257
sniSwitch := false
@@ -210,25 +260,33 @@ func dataSourceTencentCloudClbListenersRead(d *schema.ResourceData, meta interfa
210260
}
211261
mapping["sni_switch"] = sniSwitch
212262
}
213-
if listener.Scheduler != nil {
214-
mapping["scheduler"] = *listener.Scheduler
215-
}
263+
mapping["scheduler"] = listener.Scheduler
216264
if listener.HealthCheck != nil {
217265
health_check_switch := false
218266
if *listener.HealthCheck.HealthSwitch == int64(1) {
219267
health_check_switch = true
220268
}
221269
mapping["health_check_switch"] = health_check_switch
222-
mapping["health_check_time_out"] = *listener.HealthCheck.TimeOut
223-
mapping["health_check_interval_time"] = *listener.HealthCheck.IntervalTime
224-
mapping["health_check_health_num"] = *listener.HealthCheck.HealthNum
225-
mapping["health_check_unhealth_num"] = *listener.HealthCheck.UnHealthNum
270+
mapping["health_check_time_out"] = listener.HealthCheck.TimeOut
271+
mapping["health_check_interval_time"] = listener.HealthCheck.IntervalTime
272+
mapping["health_check_health_num"] = listener.HealthCheck.HealthNum
273+
mapping["health_check_unhealth_num"] = listener.HealthCheck.UnHealthNum
274+
mapping["health_check_http_code"] = listener.HealthCheck.HttpCode
275+
mapping["health_check_http_path"] = listener.HealthCheck.HttpCheckPath
276+
mapping["health_check_http_domain"] = listener.HealthCheck.HttpCheckDomain
277+
mapping["health_check_http_method"] = listener.HealthCheck.HttpCheckMethod
278+
mapping["health_check_http_version"] = listener.HealthCheck.HttpVersion
279+
mapping["health_check_context_type"] = listener.HealthCheck.ContextType
280+
mapping["health_check_send_context"] = listener.HealthCheck.SendContext
281+
mapping["health_check_recv_context"] = listener.HealthCheck.RecvContext
282+
mapping["health_check_type"] = listener.HealthCheck.CheckType
283+
mapping["health_check_port"] = listener.HealthCheck.CheckPort
226284
}
227285
if listener.Certificate != nil {
228-
mapping["certificate_ssl_mode"] = *listener.Certificate.SSLMode
229-
mapping["certificate_id"] = *listener.Certificate.CertId
286+
mapping["certificate_ssl_mode"] = listener.Certificate.SSLMode
287+
mapping["certificate_id"] = listener.Certificate.CertId
230288
if listener.Certificate.CertCaId != nil {
231-
mapping["certificate_ca_id"] = *listener.Certificate.CertCaId
289+
mapping["certificate_ca_id"] = listener.Certificate.CertCaId
232290
}
233291
}
234292
listenerList = append(listenerList, mapping)

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/data_source_tc_clb_redirections_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ resource "tencentcloud_clb_listener" "listener_basic" {
4545
4646
resource "tencentcloud_clb_listener_rule" "rule_basic" {
4747
clb_id = tencentcloud_clb_instance.clb.id
48-
listener_id = tencentcloud_clb_listener.listener_basic.id
48+
listener_id = tencentcloud_clb_listener.listener_basic.listener_id
4949
domain = "abc.com"
5050
url = "/"
5151
session_expire_time = 30
@@ -61,7 +61,7 @@ resource "tencentcloud_clb_listener" "listener_target" {
6161
6262
resource "tencentcloud_clb_listener_rule" "rule_target" {
6363
clb_id = tencentcloud_clb_instance.clb.id
64-
listener_id = tencentcloud_clb_listener.listener_target.id
64+
listener_id = tencentcloud_clb_listener.listener_target.listener_id
6565
domain = "abcd.com"
6666
url = "/"
6767
session_expire_time = 30
@@ -70,10 +70,10 @@ resource "tencentcloud_clb_listener_rule" "rule_target" {
7070
7171
resource "tencentcloud_clb_redirection" "redirection_basic" {
7272
clb_id = tencentcloud_clb_instance.clb.id
73-
source_listener_id = tencentcloud_clb_listener.listener_basic.id
74-
target_listener_id = tencentcloud_clb_listener.listener_target.id
75-
source_rule_id = tencentcloud_clb_listener_rule.rule_basic.id
76-
target_rule_id = tencentcloud_clb_listener_rule.rule_target.id
73+
source_listener_id = tencentcloud_clb_listener.listener_basic.listener_id
74+
target_listener_id = tencentcloud_clb_listener.listener_target.listener_id
75+
source_rule_id = tencentcloud_clb_listener_rule.rule_basic.rule_id
76+
target_rule_id = tencentcloud_clb_listener_rule.rule_target.rule_id
7777
}
7878
7979
data "tencentcloud_clb_redirections" "redirections" {

tencentcloud/data_source_tc_clb_target_groups.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource "tencentcloud_clb_listener" "listener_basic" {
1818
1919
resource "tencentcloud_clb_listener_rule" "rule_basic" {
2020
clb_id = tencentcloud_clb_instance.clb_basic.id
21-
listener_id = tencentcloud_clb_listener.listener_basic.id
21+
listener_id = tencentcloud_clb_listener.listener_basic.listener_id
2222
domain = "abc.com"
2323
url = "/"
2424
session_expire_time = 30
@@ -32,8 +32,8 @@ resource "tencentcloud_clb_target_group" "test"{
3232
3333
resource "tencentcloud_clb_target_group_attachment" "group" {
3434
clb_id = tencentcloud_clb_instance.clb_basic.id
35-
listener_id = tencentcloud_clb_listener.listener_basic.id
36-
rule_id = tencentcloud_clb_listener_rule.rule_basic.id
35+
listener_id = tencentcloud_clb_listener.listener_basic.listener_id
36+
rule_id = tencentcloud_clb_listener_rule.rule_basic.rule_id
3737
targrt_group_id = tencentcloud_clb_target_group.test.id
3838
}
3939

0 commit comments

Comments
 (0)