@@ -33,6 +33,11 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
33
33
Optional : true ,
34
34
Description : "The available zone that the CBS instance locates at." ,
35
35
},
36
+ "dedicated_cluster_id" : {
37
+ Type : schema .TypeString ,
38
+ Optional : true ,
39
+ Description : "Exclusive cluster id." ,
40
+ },
36
41
"project_id" : {
37
42
Type : schema .TypeInt ,
38
43
Optional : true ,
@@ -126,6 +131,11 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
126
131
Computed : true ,
127
132
Description : "The zone of CBS." ,
128
133
},
134
+ "dedicated_cluster_id" : {
135
+ Type : schema .TypeString ,
136
+ Computed : true ,
137
+ Description : "Exclusive cluster id." ,
138
+ },
129
139
"project_id" : {
130
140
Type : schema .TypeInt ,
131
141
Computed : true ,
@@ -191,25 +201,37 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
191
201
func dataSourceTencentCloudCbsStoragesRead (d * schema.ResourceData , meta interface {}) error {
192
202
defer tccommon .LogElapsed ("data_source.tencentcloud_cbs_storages.read" )()
193
203
194
- logId := tccommon .GetLogId (tccommon .ContextNil )
195
- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
204
+ var (
205
+ logId = tccommon .GetLogId (tccommon .ContextNil )
206
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
207
+ cbsService = CbsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
208
+ )
196
209
197
210
params := make (map [string ]interface {})
198
211
if v , ok := d .GetOk ("storage_id" ); ok {
199
212
params ["disk-id" ] = v .(string )
200
213
}
214
+
201
215
if v , ok := d .GetOk ("storage_name" ); ok {
202
216
params ["disk-name" ] = v .(string )
203
217
}
218
+
204
219
if v , ok := d .GetOk ("availability_zone" ); ok {
205
220
params ["zone" ] = v .(string )
206
221
}
222
+
223
+ if v , ok := d .GetOk ("dedicated_cluster_id" ); ok {
224
+ params ["dedicated-cluster-id " ] = v .(string )
225
+ }
226
+
207
227
if v , ok := d .GetOkExists ("project_id" ); ok {
208
228
params ["project-id" ] = fmt .Sprintf ("%d" , v .(int ))
209
229
}
230
+
210
231
if v , ok := d .GetOk ("storage_type" ); ok {
211
232
params ["disk-type" ] = v .(string )
212
233
}
234
+
213
235
if v , ok := d .GetOk ("storage_usage" ); ok {
214
236
params ["disk-usage" ] = v .(string )
215
237
}
@@ -229,28 +251,29 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
229
251
if v , ok := d .GetOk ("storage_state" ); ok {
230
252
params ["disk-state" ] = helper .InterfacesStringsPoint (v .([]interface {}))
231
253
}
254
+
232
255
if v , ok := d .GetOk ("instance_ips" ); ok {
233
256
params ["instance-ip-address" ] = helper .InterfacesStringsPoint (v .([]interface {}))
234
257
}
258
+
235
259
if v , ok := d .GetOk ("instance_name" ); ok {
236
260
params ["instance-name" ] = helper .InterfacesStringsPoint (v .([]interface {}))
237
261
}
262
+
238
263
if v , ok := d .GetOk ("tag_keys" ); ok {
239
264
params ["tag-key" ] = helper .InterfacesStringsPoint (v .([]interface {}))
240
265
}
266
+
241
267
if v , ok := d .GetOk ("tag_values" ); ok {
242
268
params ["tag-value" ] = helper .InterfacesStringsPoint (v .([]interface {}))
243
269
}
244
270
245
- cbsService := CbsService {
246
- client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn (),
247
- }
248
-
249
271
err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
250
272
storages , e := cbsService .DescribeDisksByFilter (ctx , params )
251
273
if e != nil {
252
274
return tccommon .RetryError (e )
253
275
}
276
+
254
277
ids := make ([]string , 0 , len (storages ))
255
278
storageList := make ([]map [string ]interface {}, 0 , len (storages ))
256
279
for _ , storage := range storages {
@@ -260,6 +283,7 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
260
283
"storage_usage" : storage .DiskUsage ,
261
284
"storage_type" : storage .DiskType ,
262
285
"availability_zone" : storage .Placement .Zone ,
286
+ "dedicated_cluster_id" : storage .Placement .DedicatedClusterId ,
263
287
"project_id" : storage .Placement .ProjectId ,
264
288
"storage_size" : storage .DiskSize ,
265
289
"attached" : storage .Attached ,
@@ -271,13 +295,16 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
271
295
"charge_type" : storage .DiskChargeType ,
272
296
"throughput_performance" : storage .ThroughputPerformance ,
273
297
}
298
+
274
299
if storage .Tags != nil {
275
300
tags := make (map [string ]interface {}, len (storage .Tags ))
276
301
for _ , t := range storage .Tags {
277
302
tags [* t .Key ] = * t .Value
278
303
}
304
+
279
305
mapping ["tags" ] = tags
280
306
}
307
+
281
308
storageList = append (storageList , mapping )
282
309
ids = append (ids , * storage .DiskId )
283
310
}
@@ -297,6 +324,7 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
297
324
298
325
return nil
299
326
})
327
+
300
328
if err != nil {
301
329
log .Printf ("[CRITAL]%s read cbs storages failed, reason:%s\n " , logId , err .Error ())
302
330
return err
0 commit comments