@@ -50,6 +50,11 @@ func DataSourceTencentCloudInstances() *schema.Resource {
5050 Optional : true ,
5151 Description : "ID of a vpc subnetwork." ,
5252 },
53+ "dedicated_cluster_id" : {
54+ Type : schema .TypeString ,
55+ Optional : true ,
56+ Description : "Exclusive cluster id." ,
57+ },
5358 "instance_set_ids" : {
5459 Type : schema .TypeList ,
5560 Optional : true ,
@@ -93,6 +98,11 @@ func DataSourceTencentCloudInstances() *schema.Resource {
9398 Computed : true ,
9499 Description : "Type of the instance." ,
95100 },
101+ "dedicated_cluster_id" : {
102+ Type : schema .TypeString ,
103+ Computed : true ,
104+ Description : "Exclusive cluster id." ,
105+ },
96106 "cpu" : {
97107 Type : schema .TypeInt ,
98108 Computed : true ,
@@ -252,33 +262,43 @@ func DataSourceTencentCloudInstances() *schema.Resource {
252262
253263func dataSourceTencentCloudInstancesRead (d * schema.ResourceData , meta interface {}) error {
254264 defer tccommon .LogElapsed ("data_source.tencentcloud_instances.read" )()
255- logId := tccommon .GetLogId (tccommon .ContextNil )
256- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
257- cvmService := CvmService {
258- client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn (),
259- }
260265
261- var instanceSetIds []* string
266+ var (
267+ logId = tccommon .GetLogId (tccommon .ContextNil )
268+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
269+ cvmService = CvmService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
270+ instanceSetIds []* string
271+ )
262272
263273 filter := make (map [string ]string )
264274 if v , ok := d .GetOk ("instance_id" ); ok {
265275 filter ["instance-id" ] = v .(string )
266276 }
277+
267278 if v , ok := d .GetOk ("instance_name" ); ok {
268279 filter ["instance-name" ] = v .(string )
269280 }
281+
270282 if v , ok := d .GetOk ("availability_zone" ); ok {
271283 filter ["zone" ] = v .(string )
272284 }
285+
273286 if v , ok := d .GetOkExists ("project_id" ); ok {
274287 filter ["project-id" ] = fmt .Sprintf ("%d" , v .(int ))
275288 }
289+
276290 if v , ok := d .GetOk ("vpc_id" ); ok {
277291 filter ["vpc-id" ] = v .(string )
278292 }
293+
279294 if v , ok := d .GetOk ("subnet_id" ); ok {
280295 filter ["subnet-id" ] = v .(string )
281296 }
297+
298+ if v , ok := d .GetOk ("dedicated_cluster_id" ); ok {
299+ filter ["dedicated-cluster-id" ] = v .(string )
300+ }
301+
282302 if v , ok := d .GetOk ("instance_set_ids" ); ok {
283303 instanceSetIds = helper .InterfacesStringsPoint (v .([]interface {}))
284304 }
@@ -296,8 +316,10 @@ func dataSourceTencentCloudInstancesRead(d *schema.ResourceData, meta interface{
296316 if errRet != nil {
297317 return tccommon .RetryError (errRet , tccommon .InternalError )
298318 }
319+
299320 return nil
300321 })
322+
301323 if err != nil {
302324 return err
303325 }
@@ -309,6 +331,7 @@ func dataSourceTencentCloudInstancesRead(d *schema.ResourceData, meta interface{
309331 "instance_id" : instance .InstanceId ,
310332 "instance_name" : instance .InstanceName ,
311333 "instance_type" : instance .InstanceType ,
334+ "dedicated_cluster_id" : instance .DedicatedClusterId ,
312335 "cpu" : instance .CPU ,
313336 "memory" : instance .Memory ,
314337 "os_name" : instance .OsName ,
@@ -332,12 +355,15 @@ func dataSourceTencentCloudInstancesRead(d *schema.ResourceData, meta interface{
332355 "instance_charge_type_prepaid_renew_flag" : instance .RenewFlag ,
333356 "cam_role_name" : instance .CamRoleName ,
334357 }
358+
335359 if len (instance .PublicIpAddresses ) > 0 {
336360 mapping ["public_ip" ] = * instance .PublicIpAddresses [0 ]
337361 }
362+
338363 if len (instance .PrivateIpAddresses ) > 0 {
339364 mapping ["private_ip" ] = * instance .PrivateIpAddresses [0 ]
340365 }
366+
341367 dataDisks := make ([]map [string ]interface {}, 0 , len (instance .DataDisks ))
342368 for _ , v := range instance .DataDisks {
343369 dataDisk := map [string ]interface {}{
@@ -346,8 +372,10 @@ func dataSourceTencentCloudInstancesRead(d *schema.ResourceData, meta interface{
346372 "data_disk_id" : v .DiskId ,
347373 "delete_with_instance" : v .DeleteWithInstance ,
348374 }
375+
349376 dataDisks = append (dataDisks , dataDisk )
350377 }
378+
351379 mapping ["data_disks" ] = dataDisks
352380 instanceList = append (instanceList , mapping )
353381 ids = append (ids , * instance .InstanceId )
@@ -366,6 +394,6 @@ func dataSourceTencentCloudInstancesRead(d *schema.ResourceData, meta interface{
366394 return err
367395 }
368396 }
369- return nil
370397
398+ return nil
371399}
0 commit comments