Skip to content

Commit 2d715f2

Browse files
committed
feat/cdc_cbs
1 parent 882eb6c commit 2d715f2

9 files changed

+198
-76
lines changed

tencentcloud/services/cbs/data_source_tc_cbs_storages.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
3333
Optional: true,
3434
Description: "The available zone that the CBS instance locates at.",
3535
},
36+
"dedicated_cluster_id": {
37+
Type: schema.TypeString,
38+
Optional: true,
39+
Description: "Exclusive cluster id.",
40+
},
3641
"project_id": {
3742
Type: schema.TypeInt,
3843
Optional: true,
@@ -126,6 +131,11 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
126131
Computed: true,
127132
Description: "The zone of CBS.",
128133
},
134+
"dedicated_cluster_id": {
135+
Type: schema.TypeString,
136+
Computed: true,
137+
Description: "Exclusive cluster id.",
138+
},
129139
"project_id": {
130140
Type: schema.TypeInt,
131141
Computed: true,
@@ -191,25 +201,37 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
191201
func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interface{}) error {
192202
defer tccommon.LogElapsed("data_source.tencentcloud_cbs_storages.read")()
193203

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+
)
196209

197210
params := make(map[string]interface{})
198211
if v, ok := d.GetOk("storage_id"); ok {
199212
params["disk-id"] = v.(string)
200213
}
214+
201215
if v, ok := d.GetOk("storage_name"); ok {
202216
params["disk-name"] = v.(string)
203217
}
218+
204219
if v, ok := d.GetOk("availability_zone"); ok {
205220
params["zone"] = v.(string)
206221
}
222+
223+
if v, ok := d.GetOk("dedicated_cluster_id"); ok {
224+
params["dedicated-cluster-id "] = v.(string)
225+
}
226+
207227
if v, ok := d.GetOkExists("project_id"); ok {
208228
params["project-id"] = fmt.Sprintf("%d", v.(int))
209229
}
230+
210231
if v, ok := d.GetOk("storage_type"); ok {
211232
params["disk-type"] = v.(string)
212233
}
234+
213235
if v, ok := d.GetOk("storage_usage"); ok {
214236
params["disk-usage"] = v.(string)
215237
}
@@ -229,28 +251,29 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
229251
if v, ok := d.GetOk("storage_state"); ok {
230252
params["disk-state"] = helper.InterfacesStringsPoint(v.([]interface{}))
231253
}
254+
232255
if v, ok := d.GetOk("instance_ips"); ok {
233256
params["instance-ip-address"] = helper.InterfacesStringsPoint(v.([]interface{}))
234257
}
258+
235259
if v, ok := d.GetOk("instance_name"); ok {
236260
params["instance-name"] = helper.InterfacesStringsPoint(v.([]interface{}))
237261
}
262+
238263
if v, ok := d.GetOk("tag_keys"); ok {
239264
params["tag-key"] = helper.InterfacesStringsPoint(v.([]interface{}))
240265
}
266+
241267
if v, ok := d.GetOk("tag_values"); ok {
242268
params["tag-value"] = helper.InterfacesStringsPoint(v.([]interface{}))
243269
}
244270

245-
cbsService := CbsService{
246-
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
247-
}
248-
249271
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
250272
storages, e := cbsService.DescribeDisksByFilter(ctx, params)
251273
if e != nil {
252274
return tccommon.RetryError(e)
253275
}
276+
254277
ids := make([]string, 0, len(storages))
255278
storageList := make([]map[string]interface{}, 0, len(storages))
256279
for _, storage := range storages {
@@ -260,6 +283,7 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
260283
"storage_usage": storage.DiskUsage,
261284
"storage_type": storage.DiskType,
262285
"availability_zone": storage.Placement.Zone,
286+
"dedicated_cluster_id": storage.Placement.DedicatedClusterId,
263287
"project_id": storage.Placement.ProjectId,
264288
"storage_size": storage.DiskSize,
265289
"attached": storage.Attached,
@@ -271,13 +295,16 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
271295
"charge_type": storage.DiskChargeType,
272296
"throughput_performance": storage.ThroughputPerformance,
273297
}
298+
274299
if storage.Tags != nil {
275300
tags := make(map[string]interface{}, len(storage.Tags))
276301
for _, t := range storage.Tags {
277302
tags[*t.Key] = *t.Value
278303
}
304+
279305
mapping["tags"] = tags
280306
}
307+
281308
storageList = append(storageList, mapping)
282309
ids = append(ids, *storage.DiskId)
283310
}
@@ -297,6 +324,7 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
297324

298325
return nil
299326
})
327+
300328
if err != nil {
301329
log.Printf("[CRITAL]%s read cbs storages failed, reason:%s\n ", logId, err.Error())
302330
return err

tencentcloud/services/cbs/data_source_tc_cbs_storages_set.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func DataSourceTencentCloudCbsStoragesSet() *schema.Resource {
3232
Optional: true,
3333
Description: "The available zone that the CBS instance locates at.",
3434
},
35+
"dedicated_cluster_id": {
36+
Type: schema.TypeString,
37+
Optional: true,
38+
Description: "Exclusive cluster id.",
39+
},
3540
"project_id": {
3641
Type: schema.TypeInt,
3742
Optional: true,
@@ -125,6 +130,11 @@ func DataSourceTencentCloudCbsStoragesSet() *schema.Resource {
125130
Computed: true,
126131
Description: "The zone of CBS.",
127132
},
133+
"dedicated_cluster_id": {
134+
Type: schema.TypeString,
135+
Computed: true,
136+
Description: "Exclusive cluster id.",
137+
},
128138
"project_id": {
129139
Type: schema.TypeInt,
130140
Computed: true,
@@ -190,25 +200,37 @@ func DataSourceTencentCloudCbsStoragesSet() *schema.Resource {
190200
func dataSourceTencentCloudCbsStoragesSetRead(d *schema.ResourceData, meta interface{}) error {
191201
defer tccommon.LogElapsed("data_source.tencentcloud_cbs_storages.read")()
192202

193-
logId := tccommon.GetLogId(tccommon.ContextNil)
194-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
203+
var (
204+
logId = tccommon.GetLogId(tccommon.ContextNil)
205+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
206+
cbsService = CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
207+
)
195208

196209
params := make(map[string]interface{})
197210
if v, ok := d.GetOk("storage_id"); ok {
198211
params["disk-id"] = v.(string)
199212
}
213+
200214
if v, ok := d.GetOk("storage_name"); ok {
201215
params["disk-name"] = v.(string)
202216
}
217+
203218
if v, ok := d.GetOk("availability_zone"); ok {
204219
params["zone"] = v.(string)
205220
}
221+
222+
if v, ok := d.GetOk("dedicated_cluster_id"); ok {
223+
params["dedicated-cluster-id "] = v.(string)
224+
}
225+
206226
if v, ok := d.GetOkExists("project_id"); ok {
207227
params["project-id"] = fmt.Sprintf("%d", v.(int))
208228
}
229+
209230
if v, ok := d.GetOk("storage_type"); ok {
210231
params["disk-type"] = v.(string)
211232
}
233+
212234
if v, ok := d.GetOk("storage_usage"); ok {
213235
params["disk-usage"] = v.(string)
214236
}
@@ -228,27 +250,28 @@ func dataSourceTencentCloudCbsStoragesSetRead(d *schema.ResourceData, meta inter
228250
if v, ok := d.GetOk("storage_state"); ok {
229251
params["disk-state"] = helper.InterfacesStringsPoint(v.([]interface{}))
230252
}
253+
231254
if v, ok := d.GetOk("instance_ips"); ok {
232255
params["instance-ip-address"] = helper.InterfacesStringsPoint(v.([]interface{}))
233256
}
257+
234258
if v, ok := d.GetOk("instance_name"); ok {
235259
params["instance-name"] = helper.InterfacesStringsPoint(v.([]interface{}))
236260
}
261+
237262
if v, ok := d.GetOk("tag_keys"); ok {
238263
params["tag-key"] = helper.InterfacesStringsPoint(v.([]interface{}))
239264
}
265+
240266
if v, ok := d.GetOk("tag_values"); ok {
241267
params["tag-value"] = helper.InterfacesStringsPoint(v.([]interface{}))
242268
}
243269

244-
cbsService := CbsService{
245-
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
246-
}
247-
248270
storages, e := cbsService.DescribeDisksInParallelByFilter(ctx, params)
249271
if e != nil {
250272
return e
251273
}
274+
252275
ids := make([]string, 0, len(storages))
253276
storageList := make([]map[string]interface{}, 0, len(storages))
254277
for _, storage := range storages {
@@ -258,6 +281,7 @@ func dataSourceTencentCloudCbsStoragesSetRead(d *schema.ResourceData, meta inter
258281
"storage_usage": storage.DiskUsage,
259282
"storage_type": storage.DiskType,
260283
"availability_zone": storage.Placement.Zone,
284+
"dedicated_cluster_id": storage.Placement.DedicatedClusterId,
261285
"project_id": storage.Placement.ProjectId,
262286
"storage_size": storage.DiskSize,
263287
"attached": storage.Attached,
@@ -269,13 +293,16 @@ func dataSourceTencentCloudCbsStoragesSetRead(d *schema.ResourceData, meta inter
269293
"charge_type": storage.DiskChargeType,
270294
"throughput_performance": storage.ThroughputPerformance,
271295
}
296+
272297
if storage.Tags != nil {
273298
tags := make(map[string]interface{}, len(storage.Tags))
274299
for _, t := range storage.Tags {
275300
tags[*t.Key] = *t.Value
276301
}
302+
277303
mapping["tags"] = tags
278304
}
305+
279306
storageList = append(storageList, mapping)
280307
ids = append(ids, *storage.DiskId)
281308
}

tencentcloud/services/cbs/extension_cbs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const (
3636
CBS_PREPAID_RENEW_FLAG_DISABLE_NOTIFY_AND_MANUAL_RENEW = "DISABLE_NOTIFY_AND_MANUAL_RENEW"
3737
CBS_CHARGE_TYPE_PREPAID = "PREPAID"
3838
CBS_CHARGE_TYPE_POSTPAID = "POSTPAID_BY_HOUR"
39+
CBS_CHARGE_TYPE_CDCPAID = "CDCPAID"
3940
)
4041

4142
var CBS_PREPAID_RENEW_FLAG = []string{
@@ -47,6 +48,7 @@ var CBS_PREPAID_RENEW_FLAG = []string{
4748
var CBS_CHARGE_TYPE = []string{
4849
CBS_CHARGE_TYPE_PREPAID,
4950
CBS_CHARGE_TYPE_POSTPAID,
51+
CBS_CHARGE_TYPE_CDCPAID,
5052
}
5153

5254
var CBS_PREPAID_PERIOD = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36}

0 commit comments

Comments
 (0)