Skip to content

Commit 3e77bac

Browse files
authored
fix(cvm): [117301871] update cvm e2e test (#2662)
* add * add * add * add * add * add
1 parent 72985be commit 3e77bac

31 files changed

+914
-231
lines changed

tencentcloud/services/cvm/data_source_tc_eips.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,42 @@ Use this data source to query eip instances.
22

33
Example Usage
44

5+
Query all eip instances
6+
7+
```hcl
8+
data "tencentcloud_eips" "example" {}
9+
```
10+
11+
Query eip instances by eip ID
12+
513
```hcl
6-
data "tencentcloud_eips" "foo" {
14+
data "tencentcloud_eips" "example" {
715
eip_id = "eip-ry9h95hg"
816
}
9-
```
17+
```
18+
19+
Query eip instances by eip name
20+
21+
```hcl
22+
data "tencentcloud_eips" "example" {
23+
eip_name = "tf-example"
24+
}
25+
```
26+
27+
Query eip instances by public ip
28+
29+
```hcl
30+
data "tencentcloud_eips" "example" {
31+
public_ip = "1.12.62.3"
32+
}
33+
```
34+
35+
Query eip instances by tags
36+
37+
```hcl
38+
data "tencentcloud_eips" "example" {
39+
tags = {
40+
"test" = "test"
41+
}
42+
}
43+
```

tencentcloud/services/cvm/data_source_tc_eips_test.go

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
99
)
1010

11-
func TestAccTencentCloudEipsDataSource(t *testing.T) {
11+
// go test -i; go test -test.run TestAccTencentCloudEipsDataSource_basic -v
12+
func TestAccTencentCloudEipsDataSource_basic(t *testing.T) {
1213
t.Parallel()
1314
resource.Test(t, resource.TestCase{
1415
PreCheck: func() { tcacctest.AccPreCheck(t) },
@@ -18,37 +19,49 @@ func TestAccTencentCloudEipsDataSource(t *testing.T) {
1819
{
1920
Config: testAccEipsDataSource,
2021
Check: resource.ComposeTestCheckFunc(
21-
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.data_eips"),
22-
resource.TestCheckResourceAttr("data.tencentcloud_eips.data_eips", "eip_list.#", "1"),
23-
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.eip_id"),
24-
resource.TestCheckResourceAttr("data.tencentcloud_eips.data_eips", "eip_list.0.eip_name", "tf-test-eip"),
25-
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.eip_type"),
26-
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.status"),
27-
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.public_ip"),
28-
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.create_time"),
29-
30-
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.tags"),
31-
resource.TestCheckResourceAttr("data.tencentcloud_eips.tags", "eip_list.0.tags.test", "test"),
22+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.example"),
23+
resource.TestCheckResourceAttr("data.tencentcloud_eips.example", "eip_list.#", "0"),
24+
25+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.example_by_id"),
26+
resource.TestCheckResourceAttr("data.tencentcloud_eips.example_by_id", "eip_list.#", "1"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.eip_id"),
28+
resource.TestCheckResourceAttr("data.tencentcloud_eips.example_by_id", "eip_list.0.eip_name", "tf-example"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.eip_type"),
30+
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.status"),
31+
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.public_ip"),
32+
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.create_time"),
33+
34+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.example_by_name"),
35+
resource.TestCheckResourceAttr("data.tencentcloud_eips.example_by_name", "eip_list.0.eip_name", "tf-example"),
36+
37+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.example_by_tags"),
38+
resource.TestCheckResourceAttr("data.tencentcloud_eips.example_by_tags", "eip_list.0.tags.test", "test"),
3239
),
3340
},
3441
},
3542
})
3643
}
3744

3845
const testAccEipsDataSource = `
39-
resource "tencentcloud_eip" "eip" {
40-
name = "tf-test-eip"
46+
resource "tencentcloud_eip" "example" {
47+
name = "tf-example"
4148
4249
tags = {
4350
"test" = "test"
4451
}
4552
}
4653
47-
data "tencentcloud_eips" "data_eips" {
48-
eip_id = tencentcloud_eip.eip.id
54+
data "tencentcloud_eips" "example" {}
55+
56+
data "tencentcloud_eips" "example_by_id" {
57+
eip_id = tencentcloud_eip.example.id
58+
}
59+
60+
data "tencentcloud_eips" "example_by_name" {
61+
eip_name = tencentcloud_eip.example.name
4962
}
5063
51-
data "tencentcloud_eips" "tags" {
52-
tags = tencentcloud_eip.eip.tags
64+
data "tencentcloud_eips" "example_by_tags" {
65+
tags = tencentcloud_eip.example.tags
5366
}
5467
`
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
Provides an available image for the user.
22

3-
The Images data source fetch proper image, which could be one of the private images of the user and images of system resources provided by TencentCloud, as well as other public images and those available on the image market.
3+
The Images data source fetch proper image, which could be one of the private images of the user and images of system
4+
resources provided by TencentCloud, as well as other public images and those available on the image market.
45

56
~> **NOTE:** This data source will be deprecated, please use `tencentcloud_images` instead.
67

78
Example Usage
89

10+
Query image
11+
912
```hcl
10-
data "tencentcloud_image" "my_favorate_image" {
11-
os_name = "centos"
13+
data "tencentcloud_image" "example" {}
14+
```
1215

16+
Query image by filter
17+
18+
```hcl
19+
data "tencentcloud_image" "example" {
1320
filter {
1421
name = "image-type"
1522
values = ["PUBLIC_IMAGE"]
1623
}
1724
}
25+
```
26+
27+
Query image by os name
28+
29+
```hcl
30+
data "tencentcloud_image" "example" {
31+
os_name = "centos"
32+
}
33+
```
34+
35+
Query image by image name regex
36+
37+
```hcl
38+
data "tencentcloud_image" "example" {
39+
image_name_regex = "^Windows\\s.*$"
40+
}
1841
```

tencentcloud/services/cvm/data_source_tc_image_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1010
)
1111

12-
func TestAccTencentCloudDataSourceImageBase(t *testing.T) {
12+
// go test -i; go test -test.run TestAccTencentCloudDataSourceImageBase_basic -v
13+
func TestAccTencentCloudDataSourceImageBase_basic(t *testing.T) {
1314
t.Parallel()
1415
resource.Test(t, resource.TestCase{
1516
PreCheck: func() { tcacctest.AccPreCheck(t) },
@@ -52,8 +53,7 @@ func TestAccTencentCloudDataSourceImageBase(t *testing.T) {
5253
}
5354

5455
const testAccTencentCloudDataSourceImageBase = `
55-
data "tencentcloud_image" "public_image" {
56-
}
56+
data "tencentcloud_image" "public_image" {}
5757
`
5858

5959
const testAccTencentCloudDataSourceImageBaseWithFilter = `

tencentcloud/services/cvm/data_source_tc_images.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,48 @@ Use this data source to query images.
22

33
Example Usage
44

5+
Query all images
6+
7+
```hcl
8+
data "tencentcloud_images" "example" {}
9+
```
10+
11+
Query images by image ID
12+
13+
```hcl
14+
data "tencentcloud_images" "example" {
15+
image_id = "img-9qrfy1xt"
16+
}
17+
```
18+
19+
Query images by os name
20+
21+
```hcl
22+
data "tencentcloud_images" "example" {
23+
os_name = "TencentOS Server 3.2 (Final)"
24+
}
25+
```
26+
27+
Query images by image name regex
28+
29+
```hcl
30+
data "tencentcloud_images" "example" {
31+
image_name_regex = "^TencentOS"
32+
}
33+
```
34+
35+
Query images by image type
36+
537
```hcl
6-
data "tencentcloud_images" "foo" {
38+
data "tencentcloud_images" "example" {
739
image_type = ["PUBLIC_IMAGE"]
8-
os_name = "centos 7.5"
940
}
10-
```
41+
```
42+
43+
Query images by instance type
44+
45+
```hcl
46+
data "tencentcloud_images" "example" {
47+
instance_type = "S1.SMALL1"
48+
}
49+
```

tencentcloud/services/cvm/data_source_tc_images_test.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
99
)
1010

11-
func TestAccTencentCloudDataSourceImagesBase(t *testing.T) {
11+
// go test -i; go test -test.run TestAccTencentCloudDataSourceImagesBase_basic -v
12+
func TestAccTencentCloudDataSourceImagesBase_basic(t *testing.T) {
1213
t.Parallel()
1314
resource.Test(t, resource.TestCase{
1415
PreCheck: func() { tcacctest.AccPreCheck(t) },
@@ -17,70 +18,70 @@ func TestAccTencentCloudDataSourceImagesBase(t *testing.T) {
1718
{
1819
Config: testAccTencentCloudDataSourceImagesBase,
1920
Check: resource.ComposeTestCheckFunc(
20-
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
21-
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
21+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
2223
),
2324
},
2425
{
2526
Config: testAccTencentCloudDataSourceImagesBaseWithFilter,
2627
Check: resource.ComposeTestCheckFunc(
27-
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
28-
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
28+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
2930
),
3031
},
3132
{
3233
Config: testAccTencentCloudDataSourceImagesBaseWithOsName,
3334
Check: resource.ComposeTestCheckFunc(
34-
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
35-
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
35+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
36+
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
3637
),
3738
},
3839
{
3940
Config: testAccTencentCloudDataSourceImagesBaseWithImageNameRegex,
4041
Check: resource.ComposeTestCheckFunc(
41-
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
42-
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
42+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
43+
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
4344
),
4445
},
4546
{
4647
Config: testAccTencentCloudDataSourceImagesBaseWithInstanceType,
4748
Check: resource.ComposeTestCheckFunc(
48-
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
49-
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
49+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
50+
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
5051
),
5152
},
5253
},
5354
})
5455
}
5556

5657
const testAccTencentCloudDataSourceImagesBase = `
57-
data "tencentcloud_images" "foo" {
58+
data "tencentcloud_images" "example" {
5859
result_output_file = "data_source_tc_images_test.txt"
5960
}
6061
`
6162

6263
const testAccTencentCloudDataSourceImagesBaseWithFilter = `
63-
data "tencentcloud_images" "foo" {
64+
data "tencentcloud_images" "example" {
6465
image_type = ["PRIVATE_IMAGE"]
6566
}
6667
`
6768

6869
const testAccTencentCloudDataSourceImagesBaseWithOsName = `
69-
data "tencentcloud_images" "foo" {
70+
data "tencentcloud_images" "example" {
7071
image_type = ["PUBLIC_IMAGE"]
71-
os_name = "CentOS 7.5"
72+
os_name = "CentOS 7.5"
7273
}
7374
`
7475

7576
const testAccTencentCloudDataSourceImagesBaseWithImageNameRegex = `
76-
data "tencentcloud_images" "foo" {
77-
image_type = ["PUBLIC_IMAGE"]
77+
data "tencentcloud_images" "example" {
78+
image_type = ["PUBLIC_IMAGE"]
7879
image_name_regex = "^CentOS\\s+7\\.5\\s+64\\w*"
7980
}
8081
`
8182

8283
const testAccTencentCloudDataSourceImagesBaseWithInstanceType = `
83-
data "tencentcloud_images" "foo" {
84+
data "tencentcloud_images" "example" {
8485
instance_type = "S1.SMALL1"
8586
}
8687
`

tencentcloud/services/cvm/data_source_tc_instance_types.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@ Use this data source to query instances type.
33
Example Usage
44

55
```hcl
6-
data "tencentcloud_instance_types" "foo" {
7-
availability_zone = "ap-guangzhou-2"
8-
cpu_core_count = 2
9-
memory_size = 4
6+
data "tencentcloud_instance_types" "example" {
7+
availability_zone = "ap-guangzhou-6"
8+
cpu_core_count = 4
9+
memory_size = 8
1010
}
11+
```
12+
13+
Complete Example
14+
15+
```hcl
16+
data "tencentcloud_instance_types" "example" {
17+
cpu_core_count = 4
18+
memory_size = 8
19+
exclude_sold_out = true
1120
12-
data tencentcloud_instance_types "t1c1g" {
13-
cpu_core_count = 1
14-
memory_size = 1
15-
exclude_sold_out=true
1621
filter {
17-
name = "instance-charge-type"
18-
values = ["POSTPAID_BY_HOUR"]
22+
name = "instance-family"
23+
values = ["SA2"]
1924
}
25+
2026
filter {
2127
name = "zone"
22-
values = ["ap-shanghai-2"]
28+
values = ["ap-guangzhou-6"]
2329
}
2430
}
2531
```

0 commit comments

Comments
 (0)