@@ -92,6 +92,32 @@ func testAccCheckClbServerAttachmentDestroy(s *terraform.State) error {
9292 return nil
9393}
9494
95+ func testAccCheckClbServerAttachmentTargetGroups (t * testing.T ) {
96+ resource .Test (t , resource.TestCase {
97+ PreCheck : func () {
98+ testAccPreCheck (t )
99+ },
100+ Providers : testAccProviders ,
101+ CheckDestroy : testAccCheckClbServerAttachmentDestroy ,
102+ Steps : []resource.TestStep {
103+ {
104+ Config : fmt .Sprintf (testAccClbServerAttachment_multiple , defaultSshCertificate ),
105+ Check : resource .ComposeTestCheckFunc (
106+ testAccCheckClbServerAttachmentExists ("tencentcloud_clb_attachment.foo" ),
107+ resource .TestCheckResourceAttr ("tencentcloud_clb_attachment.foo" , "targets.#" , "2" ),
108+ ),
109+ },
110+ {
111+ Config : fmt .Sprintf (testAccClbServerAttachment_multiple_update , defaultSshCertificate ),
112+ Check : resource .ComposeTestCheckFunc (
113+ testAccCheckClbServerAttachmentExists ("tencentcloud_clb_attachment.foo" ),
114+ resource .TestCheckResourceAttr ("tencentcloud_clb_attachment.foo" , "targets.#" , "1" ),
115+ ),
116+ },
117+ },
118+ })
119+ }
120+
95121func testAccCheckClbServerAttachmentExists (n string ) resource.TestCheckFunc {
96122 return func (s * terraform.State ) error {
97123 logId := getLogId (contextNil )
@@ -228,3 +254,98 @@ resource "tencentcloud_clb_attachment" "foo" {
228254 }
229255}
230256`
257+
258+ const testAccClbServerAttachment_multiple = instanceCommonTestCase + `
259+ resource "tencentcloud_instance" "update" {
260+ instance_name = var.instance_name_update
261+ availability_zone = data.tencentcloud_availability_zones.default.zones.0.name
262+ image_id = data.tencentcloud_images.default.images.0.image_id
263+ instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
264+ system_disk_type = "CLOUD_PREMIUM"
265+ system_disk_size = 50
266+ allocate_public_ip = true
267+ internet_max_bandwidth_out = 10
268+ vpc_id = var.vpc_id
269+ subnet_id = var.subnet_id
270+ }
271+
272+ resource "tencentcloud_clb_instance" "foo" {
273+ network_type = "OPEN"
274+ clb_name = var.instance_name
275+ vpc_id = var.vpc_id
276+ }
277+
278+ resource "tencentcloud_clb_listener" "foo" {
279+ clb_id = tencentcloud_clb_instance.foo.id
280+ listener_name = var.instance_name
281+ port = 77
282+ protocol = "HTTPS"
283+ certificate_ssl_mode = "UNIDIRECTIONAL"
284+ certificate_id = "%s"
285+ }
286+
287+ resource "tencentcloud_clb_listener_rule" "foo" {
288+ clb_id = tencentcloud_clb_instance.foo.id
289+ listener_id = tencentcloud_clb_listener.foo.id
290+ domain = "abc.com"
291+ url = "/"
292+ session_expire_time = 30
293+ scheduler = "WRR"
294+ }
295+
296+ resource "tencentcloud_clb_attachment" "foo" {
297+ clb_id = tencentcloud_clb_instance.foo.id
298+ listener_id = tencentcloud_clb_listener.foo.id
299+ rule_id = tencentcloud_clb_listener_rule.foo.id
300+
301+ targets {
302+ instance_id = tencentcloud_instance.default.id
303+ port = 23
304+ weight = 10
305+ }
306+ targets {
307+ instance_id = tencentcloud_instance.update.id
308+ port = 24
309+ weight = 10
310+ }
311+ }
312+ `
313+
314+ const testAccClbServerAttachment_multiple_update = instanceCommonTestCase + `
315+
316+ resource "tencentcloud_clb_instance" "foo" {
317+ network_type = "OPEN"
318+ clb_name = var.instance_name
319+ vpc_id = var.vpc_id
320+ }
321+
322+ resource "tencentcloud_clb_listener" "foo" {
323+ clb_id = tencentcloud_clb_instance.foo.id
324+ listener_name = var.instance_name
325+ port = 77
326+ protocol = "HTTPS"
327+ certificate_ssl_mode = "UNIDIRECTIONAL"
328+ certificate_id = "%s"
329+ }
330+
331+ resource "tencentcloud_clb_listener_rule" "foo" {
332+ clb_id = tencentcloud_clb_instance.foo.id
333+ listener_id = tencentcloud_clb_listener.foo.id
334+ domain = "abc.com"
335+ url = "/"
336+ session_expire_time = 30
337+ scheduler = "WRR"
338+ }
339+
340+ resource "tencentcloud_clb_attachment" "foo" {
341+ clb_id = tencentcloud_clb_instance.foo.id
342+ listener_id = tencentcloud_clb_listener.foo.id
343+ rule_id = tencentcloud_clb_listener_rule.foo.id
344+
345+ targets {
346+ instance_id = tencentcloud_instance.default.id
347+ port = 23
348+ weight = 10
349+ }
350+ }
351+ `
0 commit comments