Skip to content

Commit 41f2944

Browse files
authored
tencentcloud_instances support instances_ids (#1126)
* tencentcloud_instances support instances_ids * update docs
1 parent a28efe7 commit 41f2944

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

tencentcloud/data_source_tc_instances.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ func dataSourceTencentCloudInstances() *schema.Resource {
5858
Optional: true,
5959
Description: "ID of a vpc subnetwork.",
6060
},
61+
"instance_set_ids": {
62+
Type: schema.TypeList,
63+
Optional: true,
64+
MaxItems: 100,
65+
ConflictsWith: []string{"instance_id", "instance_name", "availability_zone", "project_id", "vpc_id", "subnet_id", "tags"},
66+
Elem: &schema.Schema{
67+
Type: schema.TypeString,
68+
},
69+
Description: "Instance set ids, max length is 100, conflict with other field.",
70+
},
6171
"tags": {
6272
Type: schema.TypeMap,
6373
Optional: true,
@@ -251,6 +261,8 @@ func dataSourceTencentCloudInstancesRead(d *schema.ResourceData, meta interface{
251261
client: meta.(*TencentCloudClient).apiV3Conn,
252262
}
253263

264+
var instanceSetIds []*string
265+
254266
filter := make(map[string]string)
255267
if v, ok := d.GetOk("instance_id"); ok {
256268
filter["instance-id"] = v.(string)
@@ -270,6 +282,10 @@ func dataSourceTencentCloudInstancesRead(d *schema.ResourceData, meta interface{
270282
if v, ok := d.GetOk("subnet_id"); ok {
271283
filter["subnet-id"] = v.(string)
272284
}
285+
if v, ok := d.GetOk("instance_set_ids"); ok {
286+
instanceSetIds = helper.InterfacesStringsPoint(v.([]interface{}))
287+
}
288+
273289
if v, ok := d.GetOk("tags"); ok {
274290
for key, value := range v.(map[string]interface{}) {
275291
filter["tag:"+key] = value.(string)
@@ -279,7 +295,7 @@ func dataSourceTencentCloudInstancesRead(d *schema.ResourceData, meta interface{
279295
var instances []*cvm.Instance
280296
var errRet error
281297
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
282-
instances, errRet = cvmService.DescribeInstanceByFilter(ctx, filter)
298+
instances, errRet = cvmService.DescribeInstanceByFilter(ctx, instanceSetIds, filter)
283299
if errRet != nil {
284300
return retryError(errRet, InternalError)
285301
}

tencentcloud/resource_tc_instance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func testSweepCvmInstance(region string) error {
3333
client: client.apiV3Conn,
3434
}
3535

36-
instances, err := cvmService.DescribeInstanceByFilter(ctx, nil)
36+
instances, err := cvmService.DescribeInstanceByFilter(ctx, nil, nil)
3737
if err != nil {
3838
return fmt.Errorf("get instance list error: %s", err.Error())
3939
}

tencentcloud/service_tencentcloud_cvm.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ func (me *CvmService) DescribeInstanceById(ctx context.Context, instanceId strin
7777
return
7878
}
7979

80-
func (me *CvmService) DescribeInstanceByFilter(ctx context.Context, filters map[string]string) (instances []*cvm.Instance, errRet error) {
80+
func (me *CvmService) DescribeInstanceByFilter(ctx context.Context, instancesId []*string, filters map[string]string) (instances []*cvm.Instance, errRet error) {
8181
logId := getLogId(ctx)
8282
request := cvm.NewDescribeInstancesRequest()
83-
request.Filters = make([]*cvm.Filter, 0, len(filters))
84-
for k, v := range filters {
85-
filter := cvm.Filter{
86-
Name: helper.String(k),
87-
Values: []*string{helper.String(v)},
83+
if instancesId != nil {
84+
request.InstanceIds = instancesId
85+
} else {
86+
request.Filters = make([]*cvm.Filter, 0, len(filters))
87+
for k, v := range filters {
88+
filter := cvm.Filter{
89+
Name: helper.String(k),
90+
Values: []*string{helper.String(v)},
91+
}
92+
request.Filters = append(request.Filters, &filter)
8893
}
89-
request.Filters = append(request.Filters, &filter)
9094
}
9195

9296
var offset int64 = 0

website/docs/d/instances.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The following arguments are supported:
2626
* `availability_zone` - (Optional) The available zone that the CVM instance locates at.
2727
* `instance_id` - (Optional) ID of the instances to be queried.
2828
* `instance_name` - (Optional) Name of the instances to be queried.
29+
* `instance_set_ids` - (Optional) Instance set ids, max length is 100, conflict with other field.
2930
* `project_id` - (Optional) The project CVM belongs to.
3031
* `result_output_file` - (Optional) Used to save results.
3132
* `subnet_id` - (Optional) ID of a vpc subnetwork.

0 commit comments

Comments
 (0)