diff --git a/tencentcloud/data_source_tc_cbs_storages.go b/tencentcloud/data_source_tc_cbs_storages.go index 45d1f8fd88..9556805c73 100644 --- a/tencentcloud/data_source_tc_cbs_storages.go +++ b/tencentcloud/data_source_tc_cbs_storages.go @@ -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 @@ -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, @@ -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) } @@ -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, } diff --git a/tencentcloud/data_source_tc_cbs_storages_test.go b/tencentcloud/data_source_tc_cbs_storages_test.go index 9af605433c..75b0988a82 100644 --- a/tencentcloud/data_source_tc_cbs_storages_test.go +++ b/tencentcloud/data_source_tc_cbs_storages_test.go @@ -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{ @@ -29,7 +29,6 @@ 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"), ), }, @@ -37,6 +36,24 @@ func TestAccTencentCloudCbsStoragesDataSource(t *testing.T) { }) } +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" @@ -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"] +} +` diff --git a/tencentcloud/resource_tc_cbs_storage_test.go b/tencentcloud/resource_tc_cbs_storage_test.go index b6034ba74d..6c8e65b989 100644 --- a/tencentcloud/resource_tc_cbs_storage_test.go +++ b/tencentcloud/resource_tc_cbs_storage_test.go @@ -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) }, @@ -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) }, diff --git a/tencentcloud/service_tencentcloud_cbs.go b/tencentcloud/service_tencentcloud_cbs.go index 23ac11ba88..a671fad39e 100644 --- a/tencentcloud/service_tencentcloud_cbs.go +++ b/tencentcloud/service_tencentcloud_cbs.go @@ -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) } diff --git a/website/docs/d/cbs_storages.html.markdown b/website/docs/d/cbs_storages.html.markdown index 5a14716547..d237f60054 100644 --- a/website/docs/d/cbs_storages.html.markdown +++ b/website/docs/d/cbs_storages.html.markdown @@ -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