Skip to content

fix(cvm): [117301871] update cvm e2e test #2662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions tencentcloud/services/cvm/data_source_tc_eips.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,42 @@ Use this data source to query eip instances.

Example Usage

Query all eip instances

```hcl
data "tencentcloud_eips" "example" {}
```

Query eip instances by eip ID

```hcl
data "tencentcloud_eips" "foo" {
data "tencentcloud_eips" "example" {
eip_id = "eip-ry9h95hg"
}
```
```

Query eip instances by eip name

```hcl
data "tencentcloud_eips" "example" {
eip_name = "tf-example"
}
```

Query eip instances by public ip

```hcl
data "tencentcloud_eips" "example" {
public_ip = "1.12.62.3"
}
```

Query eip instances by tags

```hcl
data "tencentcloud_eips" "example" {
tags = {
"test" = "test"
}
}
```
49 changes: 31 additions & 18 deletions tencentcloud/services/cvm/data_source_tc_eips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccTencentCloudEipsDataSource(t *testing.T) {
// go test -i; go test -test.run TestAccTencentCloudEipsDataSource_basic -v
func TestAccTencentCloudEipsDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheck(t) },
Expand All @@ -18,37 +19,49 @@ func TestAccTencentCloudEipsDataSource(t *testing.T) {
{
Config: testAccEipsDataSource,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.data_eips"),
resource.TestCheckResourceAttr("data.tencentcloud_eips.data_eips", "eip_list.#", "1"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.eip_id"),
resource.TestCheckResourceAttr("data.tencentcloud_eips.data_eips", "eip_list.0.eip_name", "tf-test-eip"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.eip_type"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.status"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.public_ip"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.data_eips", "eip_list.0.create_time"),

tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.tags"),
resource.TestCheckResourceAttr("data.tencentcloud_eips.tags", "eip_list.0.tags.test", "test"),
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.example"),
resource.TestCheckResourceAttr("data.tencentcloud_eips.example", "eip_list.#", "0"),

tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.example_by_id"),
resource.TestCheckResourceAttr("data.tencentcloud_eips.example_by_id", "eip_list.#", "1"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.eip_id"),
resource.TestCheckResourceAttr("data.tencentcloud_eips.example_by_id", "eip_list.0.eip_name", "tf-example"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.eip_type"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.status"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.public_ip"),
resource.TestCheckResourceAttrSet("data.tencentcloud_eips.example_by_id", "eip_list.0.create_time"),

tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.example_by_name"),
resource.TestCheckResourceAttr("data.tencentcloud_eips.example_by_name", "eip_list.0.eip_name", "tf-example"),

tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_eips.example_by_tags"),
resource.TestCheckResourceAttr("data.tencentcloud_eips.example_by_tags", "eip_list.0.tags.test", "test"),
),
},
},
})
}

const testAccEipsDataSource = `
resource "tencentcloud_eip" "eip" {
name = "tf-test-eip"
resource "tencentcloud_eip" "example" {
name = "tf-example"

tags = {
"test" = "test"
}
}

data "tencentcloud_eips" "data_eips" {
eip_id = tencentcloud_eip.eip.id
data "tencentcloud_eips" "example" {}

data "tencentcloud_eips" "example_by_id" {
eip_id = tencentcloud_eip.example.id
}

data "tencentcloud_eips" "example_by_name" {
eip_name = tencentcloud_eip.example.name
}

data "tencentcloud_eips" "tags" {
tags = tencentcloud_eip.eip.tags
data "tencentcloud_eips" "example_by_tags" {
tags = tencentcloud_eip.example.tags
}
`
29 changes: 26 additions & 3 deletions tencentcloud/services/cvm/data_source_tc_image.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
Provides an available image for the user.

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.
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.

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

Example Usage

Query image

```hcl
data "tencentcloud_image" "my_favorate_image" {
os_name = "centos"
data "tencentcloud_image" "example" {}
```

Query image by filter

```hcl
data "tencentcloud_image" "example" {
filter {
name = "image-type"
values = ["PUBLIC_IMAGE"]
}
}
```

Query image by os name

```hcl
data "tencentcloud_image" "example" {
os_name = "centos"
}
```

Query image by image name regex

```hcl
data "tencentcloud_image" "example" {
image_name_regex = "^Windows\\s.*$"
}
```
6 changes: 3 additions & 3 deletions tencentcloud/services/cvm/data_source_tc_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccTencentCloudDataSourceImageBase(t *testing.T) {
// go test -i; go test -test.run TestAccTencentCloudDataSourceImageBase_basic -v
func TestAccTencentCloudDataSourceImageBase_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheck(t) },
Expand Down Expand Up @@ -52,8 +53,7 @@ func TestAccTencentCloudDataSourceImageBase(t *testing.T) {
}

const testAccTencentCloudDataSourceImageBase = `
data "tencentcloud_image" "public_image" {
}
data "tencentcloud_image" "public_image" {}
`

const testAccTencentCloudDataSourceImageBaseWithFilter = `
Expand Down
45 changes: 42 additions & 3 deletions tencentcloud/services/cvm/data_source_tc_images.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,48 @@ Use this data source to query images.

Example Usage

Query all images

```hcl
data "tencentcloud_images" "example" {}
```

Query images by image ID

```hcl
data "tencentcloud_images" "example" {
image_id = "img-9qrfy1xt"
}
```

Query images by os name

```hcl
data "tencentcloud_images" "example" {
os_name = "TencentOS Server 3.2 (Final)"
}
```

Query images by image name regex

```hcl
data "tencentcloud_images" "example" {
image_name_regex = "^TencentOS"
}
```

Query images by image type

```hcl
data "tencentcloud_images" "foo" {
data "tencentcloud_images" "example" {
image_type = ["PUBLIC_IMAGE"]
os_name = "centos 7.5"
}
```
```

Query images by instance type

```hcl
data "tencentcloud_images" "example" {
instance_type = "S1.SMALL1"
}
```
37 changes: 19 additions & 18 deletions tencentcloud/services/cvm/data_source_tc_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccTencentCloudDataSourceImagesBase(t *testing.T) {
// go test -i; go test -test.run TestAccTencentCloudDataSourceImagesBase_basic -v
func TestAccTencentCloudDataSourceImagesBase_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheck(t) },
Expand All @@ -17,70 +18,70 @@ func TestAccTencentCloudDataSourceImagesBase(t *testing.T) {
{
Config: testAccTencentCloudDataSourceImagesBase,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
),
},
{
Config: testAccTencentCloudDataSourceImagesBaseWithFilter,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
),
},
{
Config: testAccTencentCloudDataSourceImagesBaseWithOsName,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
),
},
{
Config: testAccTencentCloudDataSourceImagesBaseWithImageNameRegex,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
),
},
{
Config: testAccTencentCloudDataSourceImagesBaseWithInstanceType,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.foo"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.foo", "images.#"),
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_images.example"),
resource.TestCheckResourceAttrSet("data.tencentcloud_images.example", "images.#"),
),
},
},
})
}

const testAccTencentCloudDataSourceImagesBase = `
data "tencentcloud_images" "foo" {
data "tencentcloud_images" "example" {
result_output_file = "data_source_tc_images_test.txt"
}
`

const testAccTencentCloudDataSourceImagesBaseWithFilter = `
data "tencentcloud_images" "foo" {
data "tencentcloud_images" "example" {
image_type = ["PRIVATE_IMAGE"]
}
`

const testAccTencentCloudDataSourceImagesBaseWithOsName = `
data "tencentcloud_images" "foo" {
data "tencentcloud_images" "example" {
image_type = ["PUBLIC_IMAGE"]
os_name = "CentOS 7.5"
os_name = "CentOS 7.5"
}
`

const testAccTencentCloudDataSourceImagesBaseWithImageNameRegex = `
data "tencentcloud_images" "foo" {
image_type = ["PUBLIC_IMAGE"]
data "tencentcloud_images" "example" {
image_type = ["PUBLIC_IMAGE"]
image_name_regex = "^CentOS\\s+7\\.5\\s+64\\w*"
}
`

const testAccTencentCloudDataSourceImagesBaseWithInstanceType = `
data "tencentcloud_images" "foo" {
data "tencentcloud_images" "example" {
instance_type = "S1.SMALL1"
}
`
28 changes: 17 additions & 11 deletions tencentcloud/services/cvm/data_source_tc_instance_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@ Use this data source to query instances type.
Example Usage

```hcl
data "tencentcloud_instance_types" "foo" {
availability_zone = "ap-guangzhou-2"
cpu_core_count = 2
memory_size = 4
data "tencentcloud_instance_types" "example" {
availability_zone = "ap-guangzhou-6"
cpu_core_count = 4
memory_size = 8
}
```

Complete Example

```hcl
data "tencentcloud_instance_types" "example" {
cpu_core_count = 4
memory_size = 8
exclude_sold_out = true

data tencentcloud_instance_types "t1c1g" {
cpu_core_count = 1
memory_size = 1
exclude_sold_out=true
filter {
name = "instance-charge-type"
values = ["POSTPAID_BY_HOUR"]
name = "instance-family"
values = ["SA2"]
}

filter {
name = "zone"
values = ["ap-shanghai-2"]
values = ["ap-guangzhou-6"]
}
}
```
Loading
Loading