Skip to content
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
86 changes: 85 additions & 1 deletion tencentcloud/data_source_tc_cbs_storages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ data "tencentcloud_cbs_storages" "storages" {
result_output_file = "mytestpath"
}
```

The following snippet shows the new supported query params

```hcl
data "tencentcloud_cbs_storages" "whats_new" {
charge_type = ["POSTPAID_BY_HOUR", "PREPAID"]
portable = true
storage_state = ["ATTACHED"]
instance_ips = ["10.0.0.2"]
instance_name = ["my-instance"]
tag_keys = ["foo"]
tag_values = ["bar", "baz"]
}
```

*/
package tencentcloud

Expand Down Expand Up @@ -58,6 +73,47 @@ func dataSourceTencentCloudCbsStorages() *schema.Resource {
Optional: true,
Description: "Filter by cloud disk type (`SYSTEM_DISK`: system disk | `DATA_DISK`: data disk).",
},
"charge_type": {
Type: schema.TypeList,
Optional: true,
Description: "List filter by disk charge type (`POSTPAID_BY_HOUR` | `PREPAID`).",
Elem: &schema.Schema{Type: schema.TypeString},
},
"portable": {
Type: schema.TypeBool,
Optional: true,
Description: "Filter by whether the disk is portable (Boolean `true` or `false`).",
},
"storage_state": {
Type: schema.TypeList,
Optional: true,
Description: "List filter by disk state (`UNATTACHED` | `ATTACHING` | `ATTACHED` | `DETACHING` | `EXPANDING` | `ROLLBACKING` | `TORECYCLE`).",
Elem: &schema.Schema{Type: schema.TypeString},
},
"instance_ips": {
Type: schema.TypeList,
Optional: true,
Description: "List filter by attached instance public or private IPs.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"instance_name": {
Type: schema.TypeList,
Optional: true,
Description: "List filter by attached instance name.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"tag_keys": {
Type: schema.TypeList,
Optional: true,
Description: "List filter by tag keys.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"tag_values": {
Type: schema.TypeList,
Optional: true,
Description: "List filter by tag values.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -162,7 +218,7 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)

params := make(map[string]string)
params := make(map[string]interface{})
if v, ok := d.GetOk("storage_id"); ok {
params["disk-id"] = v.(string)
}
Expand All @@ -182,6 +238,34 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
params["disk-usage"] = v.(string)
}

if v, ok := d.GetOk("charge_type"); ok {
params["disk-charge-type"] = helper.InterfacesStringsPoint(v.([]interface{}))
}

if v, ok := d.GetOk("portable"); ok {
if v.(bool) {
params["portable"] = "TRUE"
} else {
params["portable"] = "FALSE"
}
}

if v, ok := d.GetOk("storage_state"); ok {
params["disk-state"] = helper.InterfacesStringsPoint(v.([]interface{}))
}
if v, ok := d.GetOk("instance_ips"); ok {
params["instance-ip-address"] = helper.InterfacesStringsPoint(v.([]interface{}))
}
if v, ok := d.GetOk("instance_name"); ok {
params["instance-name"] = helper.InterfacesStringsPoint(v.([]interface{}))
}
if v, ok := d.GetOk("tag_keys"); ok {
params["tag-key"] = helper.InterfacesStringsPoint(v.([]interface{}))
}
if v, ok := d.GetOk("tag_values"); ok {
params["tag-value"] = helper.InterfacesStringsPoint(v.([]interface{}))
}

cbsService := CbsService{
client: meta.(*TencentCloudClient).apiV3Conn,
}
Expand Down
38 changes: 32 additions & 6 deletions tencentcloud/data_source_tc_cbs_storages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccTencentCloudCbsStoragesDataSource(t *testing.T) {
func TestAccTencentCloudCbsStoragesDataSourceId(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
Expand All @@ -29,14 +29,31 @@ func TestAccTencentCloudCbsStoragesDataSource(t *testing.T) {
resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.attached", "false"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_storages.storages", "storage_list.0.create_time"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_storages.storages", "storage_list.0.status"),
resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.tags.test", "tf"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_storages.storages", "storage_list.0.charge_type"),
),
},
},
})
}

func TestAccTencentCloudCbsStoragesDataSourceNewParams(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCbsStorageDestroy,
Steps: []resource.TestStep{
{
Config: testAccCbsStoragesDataSourceNewParams,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_storages.storages", "storage_list.#"),
),
},
},
})
}

const testAccCbsStoragesDataSource = `
resource "tencentcloud_cbs_storage" "storage" {
storage_type = "CLOUD_PREMIUM"
Expand All @@ -45,13 +62,22 @@ resource "tencentcloud_cbs_storage" "storage" {
availability_zone = "ap-guangzhou-3"
project_id = 0
encrypt = false

tags = {
test = "tf"
}
}

data "tencentcloud_cbs_storages" "storages" {
storage_id = tencentcloud_cbs_storage.storage.id
}
`

const testAccCbsStoragesDataSourceNewParams = `
data "tencentcloud_cbs_storages" "storages" {
storage_name = "disk-foo"
charge_type = ["POSTPAID_BY_HOUR", "PREPAID"]
portable = true
storage_state = ["ATTACHED"]
instance_ips = ["10.0.0.2"]
instance_name = ["my-instance"]
tag_keys = ["foo"]
tag_values = ["bar", "baz"]
}
`
2 changes: 0 additions & 2 deletions tencentcloud/resource_tc_cbs_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ func TestAccTencentCloudCbsStorage_full(t *testing.T) {
}

func TestAccTencentCloudCbsStorage_prepaid(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
Expand Down Expand Up @@ -153,7 +152,6 @@ func TestAccTencentCloudCbsStorage_prepaid(t *testing.T) {
}

func TestAccTencentCloudCbsStorage_upgrade(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
Expand Down
11 changes: 8 additions & 3 deletions tencentcloud/service_tencentcloud_cbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ func (me *CbsService) DescribeDiskList(ctx context.Context, diskIds []*string) (
return
}

func (me *CbsService) DescribeDisksByFilter(ctx context.Context, params map[string]string) (disks []*cbs.Disk, errRet error) {
func (me *CbsService) DescribeDisksByFilter(ctx context.Context, params map[string]interface{}) (disks []*cbs.Disk, errRet error) {
logId := getLogId(ctx)
request := cbs.NewDescribeDisksRequest()
request.Filters = make([]*cbs.Filter, 0, len(params))
for k, v := range params {
filter := &cbs.Filter{
Name: helper.String(k),
Values: []*string{helper.String(v)},
Name: helper.String(k),
}
switch v.(type) {
case string:
filter.Values = []*string{helper.String(v.(string))}
case []*string:
filter.Values = v.([]*string)
}
request.Filters = append(request.Filters, filter)
}
Expand Down
21 changes: 21 additions & 0 deletions website/docs/d/cbs_storages.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,38 @@ data "tencentcloud_cbs_storages" "storages" {
}
```

The following snippet shows the new supported query params

```hcl
data "tencentcloud_cbs_storages" "whats_new" {
charge_type = ["POSTPAID_BY_HOUR", "PREPAID"]
portable = true
storage_state = ["ATTACHED"]
instance_ips = ["10.0.0.2"]
instance_name = ["my-instance"]
tag_keys = ["foo"]
tag_values = ["bar", "baz"]
}
```

## Argument Reference

The following arguments are supported:

* `availability_zone` - (Optional) The available zone that the CBS instance locates at.
* `charge_type` - (Optional) List filter by disk charge type (`POSTPAID_BY_HOUR` | `PREPAID`).
* `instance_ips` - (Optional) List filter by attached instance public or private IPs.
* `instance_name` - (Optional) List filter by attached instance name.
* `portable` - (Optional) Filter by whether the disk is portable (Boolean `true` or `false`).
* `project_id` - (Optional) ID of the project with which the CBS is associated.
* `result_output_file` - (Optional) Used to save results.
* `storage_id` - (Optional) ID of the CBS to be queried.
* `storage_name` - (Optional) Name of the CBS to be queried.
* `storage_state` - (Optional) List filter by disk state (`UNATTACHED` | `ATTACHING` | `ATTACHED` | `DETACHING` | `EXPANDING` | `ROLLBACKING` | `TORECYCLE`).
* `storage_type` - (Optional) Filter by cloud disk media type (`CLOUD_BASIC`: HDD cloud disk | `CLOUD_PREMIUM`: Premium Cloud Storage | `CLOUD_SSD`: SSD cloud disk).
* `storage_usage` - (Optional) Filter by cloud disk type (`SYSTEM_DISK`: system disk | `DATA_DISK`: data disk).
* `tag_keys` - (Optional) List filter by tag keys.
* `tag_values` - (Optional) List filter by tag values.

## Attributes Reference

Expand Down