From 0b99c17b92ebd97235c5713a925be67e6fffaa2d Mon Sep 17 00:00:00 2001 From: Kagashino Date: Fri, 10 Jun 2022 15:29:21 +0800 Subject: [PATCH] fix: clb attachment - disable target diff if using TCP-SSL listener --- tencentcloud/resource_tc_clb_attachment.go | 3 +- .../resource_tc_clb_attachment_test.go | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/tencentcloud/resource_tc_clb_attachment.go b/tencentcloud/resource_tc_clb_attachment.go index f64a8411e7..b1a5a7f0b9 100644 --- a/tencentcloud/resource_tc_clb_attachment.go +++ b/tencentcloud/resource_tc_clb_attachment.go @@ -424,7 +424,8 @@ func resourceTencentCloudClbServerAttachmentRead(d *schema.ResourceData, meta in } } } - } else if *instance.Protocol == CLB_LISTENER_PROTOCOL_TCP || *instance.Protocol == CLB_LISTENER_PROTOCOL_UDP { + // TCP / UDP / TCP_SSL + } else if instance.Targets != nil { onlineTargets = instance.Targets } diff --git a/tencentcloud/resource_tc_clb_attachment_test.go b/tencentcloud/resource_tc_clb_attachment_test.go index d47c64d860..48084e76e5 100644 --- a/tencentcloud/resource_tc_clb_attachment_test.go +++ b/tencentcloud/resource_tc_clb_attachment_test.go @@ -36,6 +36,15 @@ func TestAccTencentCloudClbServerAttachment_tcp(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "protocol_type", "TCP"), resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"), ), + }, { + Config: testAccClbServerAttachment_tcp_update_ssl, + Check: resource.ComposeTestCheckFunc( + testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.foo"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "clb_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "listener_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "protocol_type", "TCP_SSL"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"), + ), }, }, }) @@ -154,6 +163,10 @@ func testAccCheckClbServerAttachmentExists(n string) resource.TestCheckFunc { } const testAccClbServerAttachment_tcp = instanceCommonTestCase + ` +data "tencentcloud_ssl_certificates" "foo" { + name = "keep" +} + resource "tencentcloud_clb_instance" "foo" { network_type = "OPEN" clb_name = "tf-clb-attach-tcp-test" @@ -187,6 +200,10 @@ resource "tencentcloud_clb_attachment" "foo" { ` const testAccClbServerAttachment_tcp_update = instanceCommonTestCase + ` +data "tencentcloud_ssl_certificates" "foo" { + name = "keep" +} + resource "tencentcloud_clb_instance" "foo" { network_type = "OPEN" clb_name = "tf-clb-attach-tcp-test" @@ -219,6 +236,41 @@ resource "tencentcloud_clb_attachment" "foo" { } ` +const testAccClbServerAttachment_tcp_update_ssl = instanceCommonTestCase + ` +data "tencentcloud_ssl_certificates" "foo" { + name = "keep" +} + +resource "tencentcloud_clb_instance" "foo" { + network_type = "OPEN" + clb_name = "tf-clb-attach-tcp-ssl" + vpc_id = var.cvm_vpc_id +} + +# This is will force new as expected +resource "tencentcloud_clb_listener" "foo" { + clb_id = tencentcloud_clb_instance.foo.id + listener_name = "tf-clb-attach-tcp-ssl" + port = 44 + protocol = "TCP_SSL" + health_check_switch = true + scheduler = "WRR" + certificate_ssl_mode = "UNIDIRECTIONAL" + certificate_id = data.tencentcloud_ssl_certificates.foo.certificates.0.id +} + +resource "tencentcloud_clb_attachment" "foo" { + clb_id = tencentcloud_clb_instance.foo.id + listener_id = tencentcloud_clb_listener.foo.listener_id + + targets { + instance_id = tencentcloud_instance.default.id + port = 23 + weight = 50 + } +} +` + const testAccClbServerAttachment_http = instanceCommonTestCase + ` resource "tencentcloud_clb_instance" "foo" { network_type = "OPEN"