Skip to content

tencentcloud_clb_listener support HTTP health check for TCP listener #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
## 1.47.1 (Unreleased)

ENHANCEMENTS:

* Resource: `tencentcloud_clb_listener` support configure HTTP health check for TCP listener([#539](https://github.com/tencentcloudstack/terraform-provider-tencentcloud/issues/539)).
* Resource: `tencentcloud_clb_listener` add computed argument `target_type`.
* Data Source: `tencentcloud_clb_listeners` support getting HTTP health check config for TCP listener.

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


## 1.47.0 (November 13, 2020)

ENHANCEMENTS:
Expand Down
93 changes: 77 additions & 16 deletions examples/tencentcloud-clb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ resource "tencentcloud_security_group" "foo" {
}

resource "tencentcloud_vpc" "foo" {
name = "example"
name = "ci-test-eni-vpc"
cidr_block = "10.0.0.0/16"
}

resource "tencentcloud_subnet" "foo" {
name = "example"
availability_zone = var.availability_zone
name = "ci-test-eni-subnet"
vpc_id = tencentcloud_vpc.foo.id
cidr_block = "10.0.0.0/24"
cidr_block = "10.0.0.0/16"
is_multicast = false
}

Expand Down Expand Up @@ -48,6 +48,11 @@ resource "tencentcloud_clb_listener" "listener_tcp" {
health_check_unhealth_num = 2
session_expire_time = 30
scheduler = "WRR"
health_check_port = 200
health_check_type = "HTTP"
health_check_http_code = 2
health_check_http_version = "HTTP/1.0"
health_check_http_method = "GET"
}

resource "tencentcloud_clb_attachment" "attachment_tcp" {
Expand All @@ -67,7 +72,7 @@ resource "tencentcloud_clb_listener" "listener_https" {
port = 443
protocol = "HTTPS"
certificate_ssl_mode = "UNIDIRECTIONAL"
certificate_id = "VfqO4zkB"
certificate_id = "f8k7ke6a"
}

resource "tencentcloud_clb_listener_rule" "rule_https" {
Expand Down Expand Up @@ -127,8 +132,8 @@ resource "tencentcloud_clb_redirection" "redirection_http" {
clb_id = tencentcloud_clb_instance.example.id
source_listener_id = tencentcloud_clb_listener.listener_http_src.listener_id
target_listener_id = tencentcloud_clb_listener.listener_http_dst.listener_id
source_rule_id = tencentcloud_clb_listener_rule.rule_http_src.listener_id
target_rule_id = tencentcloud_clb_listener_rule.rule_http_dst.listener_id
source_rule_id = tencentcloud_clb_listener_rule.rule_http_src.rule_id
target_rule_id = tencentcloud_clb_listener_rule.rule_http_dst.rule_id
}

resource "tencentcloud_clb_instance" "clb_basic" {
Expand Down Expand Up @@ -157,18 +162,74 @@ resource "tencentcloud_clb_target_group" "test"{
target_group_name = "test-target-keep-1"
}

resource "tencentcloud_clb_target_group_instance_attachment" "test"{
target_group_id = tencentcloud_clb_target_group.test.id
bind_ip = "172.16.48.18"
port = 222
weight = 3
data "tencentcloud_images" "my_favorite_image" {
image_type = ["PUBLIC_IMAGE"]
os_name = "centos"
}

data "tencentcloud_instance_types" "my_favorite_instance_types" {
filter {
name = "instance-family"
values = ["S3"]
}

cpu_core_count = 1
memory_size = 1
}

data "tencentcloud_availability_zones" "default" {
}

resource "tencentcloud_vpc" "app" {
cidr_block = "10.0.0.0/16"
name = "awesome_app_vpc"
}

resource "tencentcloud_subnet" "app" {
vpc_id = tencentcloud_vpc.app.id
availability_zone = data.tencentcloud_availability_zones.default.zones.0.name
name = "awesome_app_subnet"
cidr_block = "10.0.1.0/24"
}

resource "tencentcloud_clb_target_group_attachment" "group" {
clb_id = tencentcloud_clb_instance.clb_basic.id
listener_id = tencentcloud_clb_listener.listener_basic.listener_id
rule_id = tencentcloud_clb_listener_rule.rule_basic.rule_id
targrt_group_id = tencentcloud_clb_target_group.test.id
resource "tencentcloud_instance" "my_awesome_app" {
instance_name = "awesome_app"
availability_zone = data.tencentcloud_availability_zones.default.zones.0.name
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = 50
hostname = "user"
project_id = 0
vpc_id = tencentcloud_vpc.app.id
subnet_id = tencentcloud_subnet.app.id
internet_max_bandwidth_out = 20

data_disks {
data_disk_type = "CLOUD_PREMIUM"
data_disk_size = 50
encrypt = false
}

tags = {
tagKey = "tagValue"
}
}

data "tencentcloud_instances" "foo" {
instance_id = tencentcloud_instance.my_awesome_app.id
}

resource "tencentcloud_clb_target_group" "test_instance_attachment"{
target_group_name = "test"
vpc_id = tencentcloud_vpc.app.id
}

resource "tencentcloud_clb_target_group_instance_attachment" "test"{
target_group_id = tencentcloud_clb_target_group.test_instance_attachment.id
bind_ip = data.tencentcloud_instances.foo.instance_list[0].private_ip
port = 88
weight = 3
}

data "tencentcloud_clb_target_groups" "target_group_info_id" {
Expand Down
2 changes: 1 addition & 1 deletion tencentcloud/data_source_tc_clb_attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resource "tencentcloud_clb_listener" "foo" {

resource "tencentcloud_clb_attachment" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
listener_id = tencentcloud_clb_listener.foo.id
listener_id = tencentcloud_clb_listener.foo.listener_id

targets {
instance_id = tencentcloud_instance.default.id
Expand Down
88 changes: 73 additions & 15 deletions tencentcloud/data_source_tc_clb_listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,56 @@ func dataSourceTencentCloudClbListeners() *schema.Resource {
Computed: true,
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.",
},
"health_check_type": {
Type: schema.TypeString,
Computed: true,
Description: "Protocol used for health check.",
},
"health_check_port": {
Type: schema.TypeInt,
Computed: true,
Description: "The health check port is the port of the backend service.",
},
"health_check_http_version": {
Type: schema.TypeString,
Computed: true,
Description: "The HTTP version of the backend service.",
},
"health_check_http_code": {
Type: schema.TypeInt,
Computed: true,
Description: "HTTP health check code of TCP listener.",
},
"health_check_http_path": {
Type: schema.TypeString,
Computed: true,
Description: "HTTP health check path of TCP listener.",
},
"health_check_http_domain": {
Type: schema.TypeString,
Computed: true,
Description: "HTTP health check domain of TCP listener.",
},
"health_check_http_method": {
Type: schema.TypeString,
Computed: true,
Description: "HTTP health check method of TCP listener.",
},
"health_check_context_type": {
Type: schema.TypeString,
Computed: true,
Description: "Health check protocol.",
},
"health_check_send_context": {
Type: schema.TypeString,
Computed: true,
Description: "It represents the content of the request sent by the health check.",
},
"health_check_recv_context": {
Type: schema.TypeString,
Computed: true,
Description: "It represents the result returned by the health check.",
},
"certificate_ssl_mode": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -195,13 +245,13 @@ func dataSourceTencentCloudClbListenersRead(d *schema.ResourceData, meta interfa
for _, listener := range listeners {
mapping := map[string]interface{}{
"clb_id": clbId,
"listener_id": *listener.ListenerId,
"listener_name": *listener.ListenerName,
"protocol": *listener.Protocol,
"port": *listener.Port,
"listener_id": listener.ListenerId,
"listener_name": listener.ListenerName,
"protocol": listener.Protocol,
"port": listener.Port,
}
if listener.SessionExpireTime != nil {
mapping["session_expire_time"] = *listener.SessionExpireTime
mapping["session_expire_time"] = listener.SessionExpireTime
}
if listener.SniSwitch != nil {
sniSwitch := false
Expand All @@ -210,25 +260,33 @@ func dataSourceTencentCloudClbListenersRead(d *schema.ResourceData, meta interfa
}
mapping["sni_switch"] = sniSwitch
}
if listener.Scheduler != nil {
mapping["scheduler"] = *listener.Scheduler
}
mapping["scheduler"] = listener.Scheduler
if listener.HealthCheck != nil {
health_check_switch := false
if *listener.HealthCheck.HealthSwitch == int64(1) {
health_check_switch = true
}
mapping["health_check_switch"] = health_check_switch
mapping["health_check_time_out"] = *listener.HealthCheck.TimeOut
mapping["health_check_interval_time"] = *listener.HealthCheck.IntervalTime
mapping["health_check_health_num"] = *listener.HealthCheck.HealthNum
mapping["health_check_unhealth_num"] = *listener.HealthCheck.UnHealthNum
mapping["health_check_time_out"] = listener.HealthCheck.TimeOut
mapping["health_check_interval_time"] = listener.HealthCheck.IntervalTime
mapping["health_check_health_num"] = listener.HealthCheck.HealthNum
mapping["health_check_unhealth_num"] = listener.HealthCheck.UnHealthNum
mapping["health_check_http_code"] = listener.HealthCheck.HttpCode
mapping["health_check_http_path"] = listener.HealthCheck.HttpCheckPath
mapping["health_check_http_domain"] = listener.HealthCheck.HttpCheckDomain
mapping["health_check_http_method"] = listener.HealthCheck.HttpCheckMethod
mapping["health_check_http_version"] = listener.HealthCheck.HttpVersion
mapping["health_check_context_type"] = listener.HealthCheck.ContextType
mapping["health_check_send_context"] = listener.HealthCheck.SendContext
mapping["health_check_recv_context"] = listener.HealthCheck.RecvContext
mapping["health_check_type"] = listener.HealthCheck.CheckType
mapping["health_check_port"] = listener.HealthCheck.CheckPort
}
if listener.Certificate != nil {
mapping["certificate_ssl_mode"] = *listener.Certificate.SSLMode
mapping["certificate_id"] = *listener.Certificate.CertId
mapping["certificate_ssl_mode"] = listener.Certificate.SSLMode
mapping["certificate_id"] = listener.Certificate.CertId
if listener.Certificate.CertCaId != nil {
mapping["certificate_ca_id"] = *listener.Certificate.CertCaId
mapping["certificate_ca_id"] = listener.Certificate.CertCaId
}
}
listenerList = append(listenerList, mapping)
Expand Down
33 changes: 23 additions & 10 deletions tencentcloud/data_source_tc_clb_listeners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func TestAccTencentCloudClbListenersDataSource(t *testing.T) {
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.protocol", "TCP"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.session_expire_time", "30"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.scheduler", "WRR"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_type", "HTTP"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_port", "0"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_code", "16"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_path", "/"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_domain", "www.tencent.com"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_method", "HEAD"),
resource.TestCheckResourceAttr("data.tencentcloud_clb_listeners.listeners", "listener_list.0.health_check_http_version", "HTTP/1.1"),
),
},
},
Expand All @@ -34,21 +41,27 @@ func TestAccTencentCloudClbListenersDataSource(t *testing.T) {

const testAccClbListenersDataSource = `
resource "tencentcloud_clb_instance" "clb" {
network_type = "OPEN"
clb_name = "tf-clb-listeners"
network_type = "OPEN"
clb_name = "tf-clb-listeners"
}

resource "tencentcloud_clb_listener" "listener" {
clb_id = tencentcloud_clb_instance.clb.id
port = 1
protocol = "TCP"
listener_name = "mylistener1234"
session_expire_time = 30
scheduler = "WRR"
clb_id = tencentcloud_clb_instance.clb.id
port = 1
protocol = "TCP"
listener_name = "mylistener1234"
session_expire_time = 30
scheduler = "WRR"
health_check_type = "HTTP"
health_check_http_domain = "www.tencent.com"
health_check_http_code = 16
health_check_http_version = "HTTP/1.1"
health_check_http_method = "HEAD"
health_check_http_path = "/"
}

data "tencentcloud_clb_listeners" "listeners" {
clb_id = tencentcloud_clb_instance.clb.id
listener_id = tencentcloud_clb_listener.listener.listener_id
clb_id = tencentcloud_clb_instance.clb.id
listener_id = tencentcloud_clb_listener.listener.listener_id
}
`
12 changes: 6 additions & 6 deletions tencentcloud/data_source_tc_clb_redirections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "tencentcloud_clb_listener" "listener_basic" {

resource "tencentcloud_clb_listener_rule" "rule_basic" {
clb_id = tencentcloud_clb_instance.clb.id
listener_id = tencentcloud_clb_listener.listener_basic.id
listener_id = tencentcloud_clb_listener.listener_basic.listener_id
domain = "abc.com"
url = "/"
session_expire_time = 30
Expand All @@ -61,7 +61,7 @@ resource "tencentcloud_clb_listener" "listener_target" {

resource "tencentcloud_clb_listener_rule" "rule_target" {
clb_id = tencentcloud_clb_instance.clb.id
listener_id = tencentcloud_clb_listener.listener_target.id
listener_id = tencentcloud_clb_listener.listener_target.listener_id
domain = "abcd.com"
url = "/"
session_expire_time = 30
Expand All @@ -70,10 +70,10 @@ resource "tencentcloud_clb_listener_rule" "rule_target" {

resource "tencentcloud_clb_redirection" "redirection_basic" {
clb_id = tencentcloud_clb_instance.clb.id
source_listener_id = tencentcloud_clb_listener.listener_basic.id
target_listener_id = tencentcloud_clb_listener.listener_target.id
source_rule_id = tencentcloud_clb_listener_rule.rule_basic.id
target_rule_id = tencentcloud_clb_listener_rule.rule_target.id
source_listener_id = tencentcloud_clb_listener.listener_basic.listener_id
target_listener_id = tencentcloud_clb_listener.listener_target.listener_id
source_rule_id = tencentcloud_clb_listener_rule.rule_basic.rule_id
target_rule_id = tencentcloud_clb_listener_rule.rule_target.rule_id
}

data "tencentcloud_clb_redirections" "redirections" {
Expand Down
6 changes: 3 additions & 3 deletions tencentcloud/data_source_tc_clb_target_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "tencentcloud_clb_listener" "listener_basic" {

resource "tencentcloud_clb_listener_rule" "rule_basic" {
clb_id = tencentcloud_clb_instance.clb_basic.id
listener_id = tencentcloud_clb_listener.listener_basic.id
listener_id = tencentcloud_clb_listener.listener_basic.listener_id
domain = "abc.com"
url = "/"
session_expire_time = 30
Expand All @@ -32,8 +32,8 @@ resource "tencentcloud_clb_target_group" "test"{

resource "tencentcloud_clb_target_group_attachment" "group" {
clb_id = tencentcloud_clb_instance.clb_basic.id
listener_id = tencentcloud_clb_listener.listener_basic.id
rule_id = tencentcloud_clb_listener_rule.rule_basic.id
listener_id = tencentcloud_clb_listener.listener_basic.listener_id
rule_id = tencentcloud_clb_listener_rule.rule_basic.rule_id
targrt_group_id = tencentcloud_clb_target_group.test.id
}

Expand Down
Loading