Skip to content

Commit 00338f9

Browse files
author
ivan
committed
添加创建多实例,开启和关闭CLB安全组默认放通测试用例
1 parent 335ff4d commit 00338f9

File tree

2 files changed

+215
-36
lines changed

2 files changed

+215
-36
lines changed

tencentcloud/resource_tc_clb_instance.go

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,58 @@ resource "tencentcloud_clb_instance" "open_clb" {
3737
}
3838
```
3939
40-
Create target group
40+
Default enable
4141
4242
```hcl
43-
resource "tencentcloud_clb_target_group" "test"{
44-
target_group_name = "hello1"
45-
port = 18082
46-
target_group_instances {
47-
bind_ip = "10.0.0.4"
48-
port = 18080
43+
resource "tencentcloud_subnet" "subnet" {
44+
availability_zone = "ap-guangzhou-1"
45+
name = "sdk-feature-test"
46+
vpc_id = tencentcloud_vpc.foo.id
47+
cidr_block = "10.0.20.0/28"
48+
is_multicast = false
49+
}
50+
51+
resource "tencentcloud_security_group" "sglab" {
52+
name = "sg_o0ek7r93"
53+
description = "favourite sg"
54+
project_id = 0
55+
}
56+
57+
resource "tencentcloud_vpc" "foo" {
58+
name = "for-my-open-clb"
59+
cidr_block = "10.0.0.0/16"
60+
61+
tags = {
62+
"test" = "mytest"
4963
}
5064
}
65+
66+
resource "tencentcloud_clb_instance" "open_clb" {
67+
network_type = "OPEN"
68+
clb_name = "my-open-clb"
69+
project_id = 0
70+
vpc_id = tencentcloud_vpc.foo.id
71+
load_balancer_pass_to_target = true
72+
73+
security_groups = [tencentcloud_security_group.sglab.id]
74+
target_region_info_region = "ap-guangzhou"
75+
target_region_info_vpc_id = tencentcloud_vpc.foo.id
76+
77+
tags = {
78+
test = "open"
79+
}
80+
}
81+
```
82+
83+
CREATE multiple instance
84+
85+
```hcl
86+
resource "tencentcloud_clb_instance" "open_clb1" {
87+
network_type = "OPEN"
88+
clb_name = "hello"
89+
master_zone_id = "ap-guangzhou-3"
90+
}
91+
~
5192
```
5293
5394
Import

tencentcloud/resource_tc_clb_instance_test.go

Lines changed: 167 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func TestAccTencentCloudClbInstance_internal(t *testing.T) {
116116
})
117117
}
118118

119-
func TestAccTencentCloudClbInstanceTargetGroup(t *testing.T) {
119+
func TestAccTencentCloudClbInstance_default_enable(t *testing.T) {
120120
t.Parallel()
121121

122122
resource.Test(t, resource.TestCase{
@@ -125,23 +125,67 @@ func TestAccTencentCloudClbInstanceTargetGroup(t *testing.T) {
125125
CheckDestroy: testAccCheckClbInstanceDestroy,
126126
Steps: []resource.TestStep{
127127
{
128-
Config: testAccClbInstanceTargetGroup,
128+
Config: testAccClbInstance_default_enable,
129129
Check: resource.ComposeTestCheckFunc(
130-
testAccCheckClbInstanceExists("tencentcloud_clb_instance.target_group"),
131-
resource.TestCheckResourceAttr("tencentcloud_clb_instance.target_group", "target_group_name", "tgt_grp_test"),
132-
resource.TestCheckResourceAttr("tencentcloud_clb_instance.target_group", "port", "33"),
133-
resource.TestCheckResourceAttr("tencentcloud_clb_instance.target_group", "target_group_instances.bind_ip", "10.0.0.4"),
134-
resource.TestCheckResourceAttr("tencentcloud_clb_instance.target_group", "target_group_instances.port", "33"),
130+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.default_enable"),
131+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "network_type", "OPEN"),
132+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "clb_name", "my_open_clb"),
133+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "project_id", "0"),
134+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.default_enable", "vpc_id"),
135+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "load_balancer_pass_to_target", "true"),
136+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.default_enable", "security_groups.0"),
137+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "target_region_info_region", "ap-guangzhou"),
138+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.default_enable", "target_region_info_vpc_id"),
139+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "tags.test", "open"),
135140
),
136141
},
137142
{
138-
Config: testAccClbInstanceTargetGroupUpdate,
143+
Config: testAccClbInstance_default_enable_open,
139144
Check: resource.ComposeTestCheckFunc(
140-
testAccCheckClbInstanceExists("tencentcloud_clb_instance.target_group"),
141-
resource.TestCheckResourceAttr("tencentcloud_clb_instance.target_group", "target_group_name", "tgt_grp_test"),
142-
resource.TestCheckResourceAttr("tencentcloud_clb_instance.target_group", "port", "33"),
143-
resource.TestCheckResourceAttr("tencentcloud_clb_instance.target_group", "target_group_instances.bind_ip", "10.0.0.4"),
144-
resource.TestCheckResourceAttr("tencentcloud_clb_instance.target_group", "target_group_instances.port", "44"),
145+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.default_enable"),
146+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "network_type", "OPEN"),
147+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "clb_name", "my_open_clb"),
148+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "project_id", "0"),
149+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.default_enable", "vpc_id"),
150+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "load_balancer_pass_to_target", "true"),
151+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.default_enable", "security_groups.0"),
152+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "target_region_info_region", "ap-guangzhou"),
153+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.default_enable", "target_region_info_vpc_id"),
154+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.default_enable", "tags.test", "hello"),
155+
),
156+
},
157+
},
158+
})
159+
}
160+
161+
func TestAccTencentCloudClbInstance_multiple_instance(t *testing.T) {
162+
t.Parallel()
163+
164+
resource.Test(t, resource.TestCase{
165+
PreCheck: func() { testAccPreCheck(t) },
166+
Providers: testAccProviders,
167+
CheckDestroy: testAccCheckClbInstanceDestroy,
168+
Steps: []resource.TestStep{
169+
{
170+
Config: testAccClbInstance__multi_instance,
171+
Check: resource.ComposeTestCheckFunc(
172+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.multiple_instance"),
173+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "network_type", "OPEN"),
174+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "clb_name", "my_open_clb"),
175+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "master_zone_id", "10001"),
176+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "slave_zone_id", "10002"),
177+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "tags.test", "mytest"),
178+
),
179+
},
180+
{
181+
Config: testAccClbInstance__multi_instance_update,
182+
Check: resource.ComposeTestCheckFunc(
183+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.multiple_instance"),
184+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "network_type", "OPEN"),
185+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "clb_name", "my_open_clb"),
186+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "master_zone_id", "10001"),
187+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "slave_zone_id", "10002"),
188+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "tags.test", "open"),
145189
),
146190
},
147191
},
@@ -313,24 +357,118 @@ resource "tencentcloud_clb_instance" "clb_open" {
313357
}
314358
`
315359

316-
const testAccClbInstanceTargetGroup = `
317-
resource "tencentcloud_clb_instance" "target_group" {
318-
target_group_name = "tgt_grp_test"
319-
port = 33
320-
target_group_instances {
321-
bind_ip = "10.0.0.4"
322-
port = 18800
323-
}
360+
const testAccClbInstance_default_enable = `
361+
variable "availability_zone" {
362+
default = "ap-guangzhou-1"
363+
}
364+
365+
resource "tencentcloud_subnet" "subnet" {
366+
availability_zone = var.availability_zone
367+
name = "sdk-feature-test"
368+
vpc_id = tencentcloud_vpc.foo.id
369+
cidr_block = "10.0.20.0/28"
370+
is_multicast = false
371+
}
372+
373+
resource "tencentcloud_security_group" "sglab" {
374+
name = "sg_o0ek7r93"
375+
description = "favourite sg"
376+
project_id = 0
377+
}
378+
379+
resource "tencentcloud_vpc" "foo" {
380+
name = "for-my-open-clb"
381+
cidr_block = "10.0.0.0/16"
382+
383+
tags = {
384+
"test" = "mytest"
385+
}
386+
}
387+
388+
resource "tencentcloud_clb_instance" "default_enable" {
389+
network_type = "OPEN"
390+
clb_name = "my-open-clb"
391+
project_id = 0
392+
vpc_id = tencentcloud_vpc.foo.id
393+
load_balancer_pass_to_target = true
394+
395+
security_groups = [tencentcloud_security_group.sglab.id]
396+
target_region_info_region = "ap-guangzhou"
397+
target_region_info_vpc_id = tencentcloud_vpc.foo.id
398+
399+
tags = {
400+
test = "open"
401+
}
402+
}
403+
`
404+
405+
const testAccClbInstance_default_enable_open = `
406+
variable "availability_zone" {
407+
default = "ap-guangzhou-1"
408+
}
409+
410+
resource "tencentcloud_subnet" "subnet" {
411+
availability_zone = var.availability_zone
412+
name = "sdk-feature-test"
413+
vpc_id = tencentcloud_vpc.foo.id
414+
cidr_block = "10.0.20.0/28"
415+
is_multicast = false
416+
}
417+
418+
resource "tencentcloud_security_group" "sglab" {
419+
name = "sg_o0ek7r93"
420+
description = "favourite sg"
421+
project_id = 0
422+
}
423+
424+
resource "tencentcloud_vpc" "foo" {
425+
name = "for-my-open-clb"
426+
cidr_block = "10.0.0.0/16"
427+
428+
tags = {
429+
"test" = "mytest"
430+
}
431+
}
432+
433+
resource "tencentcloud_clb_instance" "default_enable" {
434+
network_type = "OPEN"
435+
clb_name = "my-open-clb"
436+
project_id = 0
437+
vpc_id = tencentcloud_vpc.foo.id
438+
load_balancer_pass_to_target = true
439+
440+
security_groups = [tencentcloud_security_group.sglab.id]
441+
target_region_info_region = "ap-guangzhou"
442+
target_region_info_vpc_id = tencentcloud_vpc.foo.id
443+
444+
tags = {
445+
test = "hello"
446+
}
324447
}
325448
`
326449

327-
const testAccClbInstanceTargetGroupUpdate = `
328-
resource "tencentcloud_clb_instance" "target_group" {
329-
target_group_name = "tgt_grp_test"
330-
port = 44
331-
target_group_instances {
332-
bind_ip = "10.0.0.4"
333-
port = 18800
334-
}
450+
const testAccClbInstance__multi_instance = `
451+
resource "tencentcloud_clb_instance" "multiple_instance" {
452+
network_type = "OPEN"
453+
clb_name = "my-open-clb"
454+
master_zone_id = "10001"
455+
slave_zone_id = "10002"
456+
457+
tags = {
458+
test = "open"
459+
}
460+
}
461+
`
462+
463+
const testAccClbInstance__multi_instance_update = `
464+
resource "tencentcloud_clb_instance" "multiple_instance" {
465+
network_type = "OPEN"
466+
clb_name = "my-open-clb"
467+
master_zone_id = "10001"
468+
slave_zone_id = "10002"
469+
470+
tags = {
471+
test = "open"
472+
}
335473
}
336474
`

0 commit comments

Comments
 (0)