Skip to content

Commit 0954768

Browse files
WeiMengXSWeiMengXS
andauthored
Pipeline/env testing case (#2324)
* feat: add operation * feat: cdb testing * feat: clb testing * feat: clb testing --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent b2c4a51 commit 0954768

5 files changed

+436
-0
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package tencentcloud
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
5+
"testing"
6+
)
7+
8+
func TestAccTencentCloudTestingClbInstanceResource_basic(t *testing.T) {
9+
t.Parallel()
10+
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheck(t) },
13+
Providers: testAccProviders,
14+
CheckDestroy: testAccCheckClbInstanceDestroy,
15+
Steps: []resource.TestStep{
16+
{
17+
Config: testAccTestingClbInstance_basic,
18+
Check: resource.ComposeTestCheckFunc(
19+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_basic"),
20+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_basic", "network_type", "OPEN"),
21+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_basic", "clb_name", BasicClbName),
22+
),
23+
},
24+
{
25+
ResourceName: "tencentcloud_clb_instance.clb_basic",
26+
ImportState: true,
27+
ImportStateVerify: true,
28+
ImportStateVerifyIgnore: []string{"dynamic_vip"},
29+
},
30+
},
31+
})
32+
}
33+
34+
func TestAccTencentCloudTestingClbInstanceResource_open(t *testing.T) {
35+
t.Parallel()
36+
37+
resource.Test(t, resource.TestCase{
38+
PreCheck: func() { testAccPreCheck(t) },
39+
Providers: testAccProviders,
40+
CheckDestroy: testAccCheckClbInstanceDestroy,
41+
Steps: []resource.TestStep{
42+
{
43+
Config: testAccTestingClbInstance_open,
44+
Check: resource.ComposeTestCheckFunc(
45+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_open"),
46+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "network_type", "OPEN"),
47+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "clb_name", OpenClbName),
48+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "project_id", "0"),
49+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "security_groups.#", "1"),
50+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "security_groups.0"),
51+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "target_region_info_region", "ap-guangzhou"),
52+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "target_region_info_vpc_id"),
53+
),
54+
},
55+
{
56+
Config: testAccTestingClbInstance_update_open,
57+
Check: resource.ComposeTestCheckFunc(
58+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_open"),
59+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "clb_name", OpenClbNameUpdate),
60+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "network_type", "OPEN"),
61+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "project_id", "0"),
62+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "vpc_id"),
63+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "security_groups.#", "1"),
64+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "security_groups.0"),
65+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "target_region_info_region", "ap-guangzhou"),
66+
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "target_region_info_vpc_id"),
67+
),
68+
},
69+
},
70+
})
71+
}
72+
73+
func TestAccTencentCloudClbTestingInstanceResource_multiple_instance(t *testing.T) {
74+
t.Parallel()
75+
76+
resource.Test(t, resource.TestCase{
77+
PreCheck: func() { testAccPreCheck(t) },
78+
Providers: testAccProviders,
79+
CheckDestroy: testAccCheckClbInstanceDestroy,
80+
Steps: []resource.TestStep{
81+
{
82+
Config: testAccTestingClbInstance_Multi_Instance,
83+
Check: resource.ComposeTestCheckFunc(
84+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.multiple_instance"),
85+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "network_type", "OPEN"),
86+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "clb_name", MultiClbName),
87+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "master_zone_id", "100004"),
88+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "slave_zone_id", "100003"),
89+
),
90+
},
91+
{
92+
Config: testAccTestingClbInstance_Multi_Instance_Update,
93+
Check: resource.ComposeTestCheckFunc(
94+
testAccCheckClbInstanceExists("tencentcloud_clb_instance.multiple_instance"),
95+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "network_type", "OPEN"),
96+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "clb_name", MultiClbName),
97+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "master_zone_id", "100004"),
98+
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "slave_zone_id", "100003"),
99+
),
100+
},
101+
},
102+
})
103+
}
104+
105+
const testAccTestingClbInstance_basic = `
106+
resource "tencentcloud_clb_instance" "clb_basic" {
107+
network_type = "OPEN"
108+
clb_name = "` + BasicClbName + `"
109+
}
110+
`
111+
112+
const testAccTestingClbInstance_open = `
113+
resource "tencentcloud_security_group" "foo" {
114+
name = "keep-ci-temp-test-sg"
115+
}
116+
117+
resource "tencentcloud_vpc" "foo" {
118+
name = "clb-instance-open-vpc"
119+
cidr_block = "10.0.0.0/16"
120+
}
121+
122+
resource "tencentcloud_clb_instance" "clb_open" {
123+
network_type = "OPEN"
124+
clb_name = "` + OpenClbName + `"
125+
project_id = 0
126+
vpc_id = tencentcloud_vpc.foo.id
127+
target_region_info_region = "ap-guangzhou"
128+
target_region_info_vpc_id = tencentcloud_vpc.foo.id
129+
security_groups = [tencentcloud_security_group.foo.id]
130+
}
131+
`
132+
const testAccTestingClbInstance_update_open = `
133+
resource "tencentcloud_security_group" "foo" {
134+
name = "clb-instance-sg"
135+
}
136+
137+
resource "tencentcloud_vpc" "foo" {
138+
name = "clb-instance-open-vpc"
139+
cidr_block = "10.0.0.0/16"
140+
}
141+
142+
resource "tencentcloud_clb_instance" "clb_open" {
143+
network_type = "OPEN"
144+
clb_name = "` + OpenClbNameUpdate + `"
145+
vpc_id = tencentcloud_vpc.foo.id
146+
project_id = 0
147+
target_region_info_region = "ap-guangzhou"
148+
target_region_info_vpc_id = tencentcloud_vpc.foo.id
149+
security_groups = [tencentcloud_security_group.foo.id]
150+
}
151+
`
152+
const testAccTestingClbInstance_Multi_Instance = `
153+
resource "tencentcloud_clb_instance" "multiple_instance" {
154+
network_type = "OPEN"
155+
clb_name = "` + MultiClbName + `"
156+
master_zone_id = "100004"
157+
slave_zone_id = "100003"
158+
}
159+
`
160+
161+
const testAccTestingClbInstance_Multi_Instance_Update = `
162+
resource "tencentcloud_clb_instance" "multiple_instance" {
163+
network_type = "OPEN"
164+
clb_name = "` + MultiClbName + `"
165+
master_zone_id = "100004"
166+
slave_zone_id = "100003"
167+
}
168+
`
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package tencentcloud
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
5+
"testing"
6+
)
7+
8+
func TestAccTencentCloudTestingClbListener_basic(t *testing.T) {
9+
t.Parallel()
10+
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheck(t) },
13+
Providers: testAccProviders,
14+
CheckDestroy: testAccCheckClbListenerDestroy,
15+
Steps: []resource.TestStep{
16+
{
17+
Config: testAccClbTestingListener_basic,
18+
Check: resource.ComposeTestCheckFunc(
19+
testAccCheckClbListenerExists("tencentcloud_clb_listener.listener_basic"),
20+
resource.TestCheckResourceAttrSet("tencentcloud_clb_listener.listener_basic", "clb_id"),
21+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "protocol", "TCP"),
22+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "listener_name", "listener_basic"),
23+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "session_expire_time", "30"),
24+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "port", "1"),
25+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "scheduler", "WRR"),
26+
),
27+
},
28+
{
29+
Config: testAccClbTestingListenerUpdate_basic,
30+
Check: resource.ComposeTestCheckFunc(
31+
testAccCheckClbListenerExists("tencentcloud_clb_listener.listener_basic"),
32+
resource.TestCheckResourceAttrSet("tencentcloud_clb_listener.listener_basic", "clb_id"),
33+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "protocol", "TCP"),
34+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "listener_name", "listener_basic_update"),
35+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "session_expire_time", "30"),
36+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "port", "1"),
37+
resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "scheduler", "WRR"),
38+
),
39+
},
40+
{
41+
ResourceName: "tencentcloud_clb_listener.listener_basic",
42+
ImportState: true,
43+
ImportStateVerify: true,
44+
},
45+
},
46+
})
47+
}
48+
49+
const testAccClbTestingListener_basic = `
50+
resource "tencentcloud_clb_instance" "clb_basic" {
51+
network_type = "OPEN"
52+
clb_name = "tf-clb-listener-basic"
53+
}
54+
55+
resource "tencentcloud_clb_listener" "listener_basic" {
56+
clb_id = tencentcloud_clb_instance.clb_basic.id
57+
port = 1
58+
protocol = "TCP"
59+
listener_name = "listener_basic"
60+
session_expire_time = 30
61+
scheduler = "WRR"
62+
target_type = "TARGETGROUP"
63+
}
64+
`
65+
const testAccClbTestingListenerUpdate_basic = `
66+
resource "tencentcloud_clb_instance" "clb_basic" {
67+
network_type = "OPEN"
68+
clb_name = "tf-clb-listener-basic"
69+
}
70+
resource "tencentcloud_clb_listener" "listener_basic" {
71+
clb_id = tencentcloud_clb_instance.clb_basic.id
72+
port = 1
73+
protocol = "TCP"
74+
listener_name = "listener_basic_update"
75+
session_expire_time = 30
76+
scheduler = "WRR"
77+
target_type = "TARGETGROUP"
78+
}
79+
`
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudTestingClbSecurityGroupAttachmentResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccTestingClbSecurityGroupAttachment,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_clb_security_group_attachment.security_group_attachment", "id")),
20+
},
21+
{
22+
ResourceName: "tencentcloud_clb_security_group_attachment.security_group_attachment",
23+
ImportState: true,
24+
ImportStateVerify: true,
25+
},
26+
},
27+
})
28+
}
29+
30+
const testAccTestingClbSecurityGroupAttachment = `
31+
32+
resource "tencentcloud_clb_security_group_attachment" "security_group_attachment" {
33+
security_group = "sg-46x20487"
34+
load_balancer_ids = ["lb-d72hklcc"]
35+
}
36+
37+
`
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package tencentcloud
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
5+
"testing"
6+
)
7+
8+
func TestAccTencentCloudTestingClbTGAttachmentInstance_basic(t *testing.T) {
9+
t.Parallel()
10+
resource.Test(t, resource.TestCase{
11+
PreCheck: func() { testAccPreCheck(t) },
12+
Providers: testAccProviders,
13+
CheckDestroy: testAccCheckClbTGAttachmentInstanceDestroy,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccTestingClbTGAttachmentInstance_basic,
17+
Check: resource.ComposeTestCheckFunc(
18+
testAccCheckClbTGAttachmentInstanceExists("tencentcloud_clb_target_group_instance_attachment.test"),
19+
resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_instance_attachment.test", "target_group_id"),
20+
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "bind_ip", "172.16.0.17"),
21+
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "port", "99"),
22+
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "weight", "3"),
23+
),
24+
},
25+
{
26+
Config: testAccTestingClbTGAttachmentInstance_update,
27+
Check: resource.ComposeTestCheckFunc(
28+
testAccCheckClbTGAttachmentInstanceExists("tencentcloud_clb_target_group_instance_attachment.test"),
29+
resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_instance_attachment.test", "target_group_id"),
30+
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "bind_ip", "172.16.0.17"),
31+
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "port", "99"),
32+
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "weight", "5"),
33+
),
34+
},
35+
},
36+
})
37+
}
38+
39+
const testAccTestingClbTGAttachmentInstance_basic = `
40+
41+
resource "tencentcloud_clb_target_group" "test"{
42+
target_group_name = "test"
43+
vpc_id = "vpc-humgpppd"
44+
}
45+
46+
resource "tencentcloud_clb_target_group_instance_attachment" "test"{
47+
target_group_id = tencentcloud_clb_target_group.test.id
48+
bind_ip = "172.16.0.17"
49+
port = 99
50+
weight = 3
51+
}
52+
`
53+
54+
const testAccTestingClbTGAttachmentInstance_update = `
55+
56+
resource "tencentcloud_clb_target_group" "test"{
57+
target_group_name = "test"
58+
vpc_id = "vpc-humgpppd"
59+
}
60+
61+
resource "tencentcloud_clb_target_group_instance_attachment" "test"{
62+
target_group_id = tencentcloud_clb_target_group.test.id
63+
bind_ip = "172.16.0.17"
64+
port = 99
65+
weight = 5
66+
}
67+
`

0 commit comments

Comments
 (0)