diff --git a/tencentcloud/basic_test.go b/tencentcloud/basic_test.go index c928286623..672254d14f 100644 --- a/tencentcloud/basic_test.go +++ b/tencentcloud/basic_test.go @@ -1130,3 +1130,21 @@ variable "instance_id" { ` // End of Clickhouse + +// CLB +const clbTargetEniTestCase = instanceCommonTestCase + ` +resource "tencentcloud_eni" "clb_eni_target" { + name = "ci-test-eni" + vpc_id = var.cvm_vpc_id + subnet_id = var.cvm_subnet_id + description = "clb eni backend" + ipv4_count = 1 +} + +resource "tencentcloud_eni_attachment" "foo" { + eni_id = tencentcloud_eni.clb_eni_target.id + instance_id = tencentcloud_instance.default.id +} +` + +//End of Clb diff --git a/tencentcloud/resource_tc_clb_attachment.go b/tencentcloud/resource_tc_clb_attachment.go index a10d589b5b..f1d03d66ed 100644 --- a/tencentcloud/resource_tc_clb_attachment.go +++ b/tencentcloud/resource_tc_clb_attachment.go @@ -529,7 +529,7 @@ func targetGroupContainsEni(targets []*clb.Backend, eniIp interface{}) (contains return } for _, target := range targets { - if len(target.PrivateIpAddresses) > 0 && target.PrivateIpAddresses[0] != nil { + if len(target.PrivateIpAddresses) == 0 && target.PrivateIpAddresses[0] == nil { continue } if ip == *target.PrivateIpAddresses[0] { diff --git a/tencentcloud/resource_tc_clb_attachment_test.go b/tencentcloud/resource_tc_clb_attachment_test.go index 303700d2bd..4261e15013 100644 --- a/tencentcloud/resource_tc_clb_attachment_test.go +++ b/tencentcloud/resource_tc_clb_attachment_test.go @@ -21,29 +21,29 @@ func TestAccTencentCloudClbAttachmentResource_tcp(t *testing.T) { { Config: testAccClbServerAttachment_tcp, 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"), - resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"), + testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_tcp"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "clb_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "listener_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "protocol_type", "TCP"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "targets.#", "1"), ), }, { Config: testAccClbServerAttachment_tcp_update, 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"), - resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"), + testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_tcp"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "clb_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "listener_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "protocol_type", "TCP"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "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"), + testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_tcp"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "clb_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "listener_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "protocol_type", "TCP_SSL"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "targets.#", "1"), ), }, }, @@ -60,25 +60,25 @@ func TestAccTencentCloudClbAttachmentResource_http(t *testing.T) { { Config: fmt.Sprintf(testAccClbServerAttachment_http, defaultSshCertificate), 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", "HTTPS"), - resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "2"), + testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_http"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_http", "clb_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_http", "listener_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_http", "protocol_type", "HTTPS"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_http", "targets.#", "2"), ), }, { Config: fmt.Sprintf(testAccClbServerAttachment_httpUpdate, defaultSshCertificate), 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", "HTTPS"), - resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"), + testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_http"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_http", "clb_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_http", "listener_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_http", "protocol_type", "HTTPS"), + resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_http", "targets.#", "1"), ), }, { - ResourceName: "tencentcloud_clb_attachment.foo", + ResourceName: "tencentcloud_clb_attachment.clb_attachment_http", ImportState: true, ImportStateVerify: true, }, @@ -172,15 +172,15 @@ func testAccCheckClbServerAttachmentExists(n string) resource.TestCheckFunc { } } -const testAccClbServerAttachment_tcp = instanceCommonTestCase + ` -resource "tencentcloud_clb_instance" "foo" { +const testAccClbServerAttachment_tcp = clbTargetEniTestCase + ` +resource "tencentcloud_clb_instance" "clb_instance_tcp" { network_type = "OPEN" clb_name = "tf-clb-attach-tcp-test" vpc_id = var.cvm_vpc_id } -resource "tencentcloud_clb_listener" "foo" { - clb_id = tencentcloud_clb_instance.foo.id +resource "tencentcloud_clb_listener" "clb_listener_tcp" { + clb_id = tencentcloud_clb_instance.clb_instance_tcp.id listener_name = "tf-clb-attach-tcp-test" port = 44 protocol = "TCP" @@ -193,9 +193,9 @@ resource "tencentcloud_clb_listener" "foo" { scheduler = "WRR" } -resource "tencentcloud_clb_attachment" "foo" { - clb_id = tencentcloud_clb_instance.foo.id - listener_id = tencentcloud_clb_listener.foo.listener_id +resource "tencentcloud_clb_attachment" "clb_attachment_tcp" { + clb_id = tencentcloud_clb_instance.clb_instance_tcp.id + listener_id = tencentcloud_clb_listener.clb_listener_tcp.listener_id targets { instance_id = tencentcloud_instance.default.id @@ -205,16 +205,16 @@ resource "tencentcloud_clb_attachment" "foo" { } ` -const testAccClbServerAttachment_tcp_update = instanceCommonTestCase + presetCVM + ` -resource "tencentcloud_clb_instance" "foo" { +const testAccClbServerAttachment_tcp_update = clbTargetEniTestCase + presetCVM + ` +resource "tencentcloud_clb_instance" "clb_instance_tcp" { network_type = "OPEN" clb_name = "tf-clb-attach-tcp-test" vpc_id = var.cvm_vpc_id snat_pro = true } -resource "tencentcloud_clb_listener" "foo" { - clb_id = tencentcloud_clb_instance.foo.id +resource "tencentcloud_clb_listener" "clb_listener_tcp" { + clb_id = tencentcloud_clb_instance.clb_instance_tcp.id listener_name = "tf-clb-attach-tcp-test" port = 44 protocol = "TCP" @@ -227,24 +227,24 @@ resource "tencentcloud_clb_listener" "foo" { scheduler = "WRR" } -resource "tencentcloud_clb_attachment" "foo" { - clb_id = tencentcloud_clb_instance.foo.id - listener_id = tencentcloud_clb_listener.foo.listener_id +resource "tencentcloud_clb_attachment" "clb_attachment_tcp" { + clb_id = tencentcloud_clb_instance.clb_instance_tcp.id + listener_id = tencentcloud_clb_listener.clb_listener_tcp.listener_id targets { - eni_ip = local.cvm_private_ip + eni_ip = tencentcloud_eni.clb_eni_target.ipv4_info.0.ip port = 23 weight = 50 } } ` -const testAccClbServerAttachment_tcp_update_ssl = instanceCommonTestCase + presetCVM + ` +const testAccClbServerAttachment_tcp_update_ssl = clbTargetEniTestCase + presetCVM + ` data "tencentcloud_ssl_certificates" "foo" { name = "keep-svr-ca" } -resource "tencentcloud_clb_instance" "foo" { +resource "tencentcloud_clb_instance" "clb_instance_tcp" { network_type = "OPEN" clb_name = "tf-clb-attach-tcp-ssl" vpc_id = var.cvm_vpc_id @@ -252,8 +252,8 @@ resource "tencentcloud_clb_instance" "foo" { } # This is will force new as expected -resource "tencentcloud_clb_listener" "foo" { - clb_id = tencentcloud_clb_instance.foo.id +resource "tencentcloud_clb_listener" "clb_listener_tcp" { + clb_id = tencentcloud_clb_instance.clb_instance_tcp.id listener_name = "tf-clb-attach-tcp-ssl" port = 44 protocol = "TCP_SSL" @@ -263,13 +263,13 @@ resource "tencentcloud_clb_listener" "foo" { 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 +resource "tencentcloud_clb_attachment" "clb_attachment_tcp" { + clb_id = tencentcloud_clb_instance.clb_instance_tcp.id + listener_id = tencentcloud_clb_listener.clb_listener_tcp.listener_id # cross network target targets { - eni_ip = local.cvm_private_ip + eni_ip = tencentcloud_eni.clb_eni_target.ipv4_info.0.ip port = 23 weight = 50 } @@ -277,14 +277,14 @@ resource "tencentcloud_clb_attachment" "foo" { ` const testAccClbServerAttachment_http = instanceCommonTestCase + presetCVM + ` -resource "tencentcloud_clb_instance" "foo" { +resource "tencentcloud_clb_instance" "clb_instance_http" { network_type = "OPEN" clb_name = "tf-clb-attach-http-test" vpc_id = var.cvm_vpc_id } -resource "tencentcloud_clb_listener" "foo" { - clb_id = tencentcloud_clb_instance.foo.id +resource "tencentcloud_clb_listener" "clb_listener_http" { + clb_id = tencentcloud_clb_instance.clb_instance_http.id listener_name = "tf-clb-attach-http-test" port = 77 protocol = "HTTPS" @@ -292,19 +292,19 @@ resource "tencentcloud_clb_listener" "foo" { certificate_id = "%s" } -resource "tencentcloud_clb_listener_rule" "foo" { - clb_id = tencentcloud_clb_instance.foo.id - listener_id = tencentcloud_clb_listener.foo.listener_id +resource "tencentcloud_clb_listener_rule" "clb_listener_rule_http" { + clb_id = tencentcloud_clb_instance.clb_instance_http.id + listener_id = tencentcloud_clb_listener.clb_listener_http.listener_id domain = "abc.com" url = "/" session_expire_time = 30 scheduler = "WRR" } -resource "tencentcloud_clb_attachment" "foo" { - clb_id = tencentcloud_clb_instance.foo.id - listener_id = tencentcloud_clb_listener.foo.listener_id - rule_id = tencentcloud_clb_listener_rule.foo.rule_id +resource "tencentcloud_clb_attachment" "clb_attachment_http" { + clb_id = tencentcloud_clb_instance.clb_instance_http.id + listener_id = tencentcloud_clb_listener.clb_listener_http.listener_id + rule_id = tencentcloud_clb_listener_rule.clb_listener_rule_http.rule_id targets { instance_id = tencentcloud_instance.default.id @@ -320,14 +320,14 @@ resource "tencentcloud_clb_attachment" "foo" { ` const testAccClbServerAttachment_httpUpdate = instanceCommonTestCase + presetCVM + ` -resource "tencentcloud_clb_instance" "foo" { +resource "tencentcloud_clb_instance" "clb_instance_http" { network_type = "OPEN" clb_name = "tf-clb-attach-http-test" vpc_id = var.cvm_vpc_id } -resource "tencentcloud_clb_listener" "foo" { - clb_id = tencentcloud_clb_instance.foo.id +resource "tencentcloud_clb_listener" "clb_listener_http" { + clb_id = tencentcloud_clb_instance.clb_instance_http.id listener_name = "tf-clb-attach-http-test" port = 77 protocol = "HTTPS" @@ -335,23 +335,23 @@ resource "tencentcloud_clb_listener" "foo" { certificate_id = "%s" } -resource "tencentcloud_clb_listener_rule" "foo" { - clb_id = tencentcloud_clb_instance.foo.id - listener_id = tencentcloud_clb_listener.foo.listener_id +resource "tencentcloud_clb_listener_rule" "clb_listener_rule_http" { + clb_id = tencentcloud_clb_instance.clb_instance_http.id + listener_id = tencentcloud_clb_listener.clb_listener_http.listener_id domain = "abc.com" url = "/" session_expire_time = 30 scheduler = "WRR" } -resource "tencentcloud_clb_attachment" "foo" { - clb_id = tencentcloud_clb_instance.foo.id - listener_id = tencentcloud_clb_listener.foo.listener_id - rule_id = tencentcloud_clb_listener_rule.foo.rule_id +resource "tencentcloud_clb_attachment" "clb_attachment_http" { + clb_id = tencentcloud_clb_instance.clb_instance_http.id + listener_id = tencentcloud_clb_listener.clb_listener_http.listener_id + rule_id = tencentcloud_clb_listener_rule.clb_listener_rule_http.rule_id targets { instance_id = tencentcloud_instance.default.id - port = 23 + port = 24 weight = 10 } } diff --git a/tencentcloud/resource_tc_clb_instance.go b/tencentcloud/resource_tc_clb_instance.go index 56d30aae59..41993f1fba 100644 --- a/tencentcloud/resource_tc_clb_instance.go +++ b/tencentcloud/resource_tc_clb_instance.go @@ -832,7 +832,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac request.DeleteProtect = &isDeleteProtect } - immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "project_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "snat_pro", "zone_id"} + immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "project_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "zone_id"} for _, v := range immutableArgs { if d.HasChange(v) {