Skip to content

feat(cbs): [118298141] support CDC #2715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changelog/2715.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:enhancement
resource/tencentcloud_cbs_storage: add params `dedicated_cluster_id`
```

```release-note:enhancement
resource/tencentcloud_cbs_storage_set: add params `dedicated_cluster_id`
```

```release-note:enhancement
data_source/tencentcloud_cbs_storages: add params `dedicated_cluster_id`
```

```release-note:enhancement
data_source/tencentcloud_cbs_storages_set: add params `dedicated_cluster_id`
```
42 changes: 35 additions & 7 deletions tencentcloud/services/cbs/data_source_tc_cbs_storages.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
Optional: true,
Description: "The available zone that the CBS instance locates at.",
},
"dedicated_cluster_id": {
Type: schema.TypeString,
Optional: true,
Description: "Exclusive cluster id.",
},
"project_id": {
Type: schema.TypeInt,
Optional: true,
Expand All @@ -52,7 +57,7 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
"charge_type": {
Type: schema.TypeList,
Optional: true,
Description: "List filter by disk charge type (`POSTPAID_BY_HOUR` | `PREPAID`).",
Description: "List filter by disk charge type (`POSTPAID_BY_HOUR` | `PREPAID` | `CDCPAID` | `DEDICATED_CLUSTER_PAID`).",
Elem: &schema.Schema{Type: schema.TypeString},
},
"portable": {
Expand Down Expand Up @@ -126,6 +131,11 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
Computed: true,
Description: "The zone of CBS.",
},
"dedicated_cluster_id": {
Type: schema.TypeString,
Computed: true,
Description: "Exclusive cluster id.",
},
"project_id": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -191,25 +201,37 @@ func DataSourceTencentCloudCbsStorages() *schema.Resource {
func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_cbs_storages.read")()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
cbsService = CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
)

params := make(map[string]interface{})
if v, ok := d.GetOk("storage_id"); ok {
params["disk-id"] = v.(string)
}

if v, ok := d.GetOk("storage_name"); ok {
params["disk-name"] = v.(string)
}

if v, ok := d.GetOk("availability_zone"); ok {
params["zone"] = v.(string)
}

if v, ok := d.GetOk("dedicated_cluster_id"); ok {
params["dedicated-cluster-id"] = v.(string)
}

if v, ok := d.GetOkExists("project_id"); ok {
params["project-id"] = fmt.Sprintf("%d", v.(int))
}

if v, ok := d.GetOk("storage_type"); ok {
params["disk-type"] = v.(string)
}

if v, ok := d.GetOk("storage_usage"); ok {
params["disk-usage"] = v.(string)
}
Expand All @@ -229,28 +251,29 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
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.(tccommon.ProviderMeta).GetAPIV3Conn(),
}

err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
storages, e := cbsService.DescribeDisksByFilter(ctx, params)
if e != nil {
return tccommon.RetryError(e)
}

ids := make([]string, 0, len(storages))
storageList := make([]map[string]interface{}, 0, len(storages))
for _, storage := range storages {
Expand All @@ -260,6 +283,7 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
"storage_usage": storage.DiskUsage,
"storage_type": storage.DiskType,
"availability_zone": storage.Placement.Zone,
"dedicated_cluster_id": storage.Placement.DedicatedClusterId,
"project_id": storage.Placement.ProjectId,
"storage_size": storage.DiskSize,
"attached": storage.Attached,
Expand All @@ -271,13 +295,16 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac
"charge_type": storage.DiskChargeType,
"throughput_performance": storage.ThroughputPerformance,
}

if storage.Tags != nil {
tags := make(map[string]interface{}, len(storage.Tags))
for _, t := range storage.Tags {
tags[*t.Key] = *t.Value
}

mapping["tags"] = tags
}

storageList = append(storageList, mapping)
ids = append(ids, *storage.DiskId)
}
Expand All @@ -297,6 +324,7 @@ func dataSourceTencentCloudCbsStoragesRead(d *schema.ResourceData, meta interfac

return nil
})

if err != nil {
log.Printf("[CRITAL]%s read cbs storages failed, reason:%s\n ", logId, err.Error())
return err
Expand Down
30 changes: 22 additions & 8 deletions tencentcloud/services/cbs/data_source_tc_cbs_storages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ Use this data source to query detailed information of CBS storages.

Example Usage

Query all CBS storages
```hcl
data "tencentcloud_cbs_storages" "storages" {
storage_id = "disk-kdt0sq6m"
result_output_file = "mytestpath"
data "tencentcloud_cbs_storages" "example" {}
```

Query CBS by storage id

```hcl
data "tencentcloud_cbs_storages" "example" {
storage_id = "disk-6goq404g"
result_output_file = "my-test-path"
}
```

Query CBS by dedicated cluster id
```hcl
data "tencentcloud_cbs_storages" "example" {
dedicated_cluster_id = "cluster-262n63e8"
}
```

The following snippet shows the new supported query params

```hcl
data "tencentcloud_cbs_storages" "whats_new" {
charge_type = ["POSTPAID_BY_HOUR", "PREPAID"]
portable = true
charge_type = ["POSTPAID_BY_HOUR", "PREPAID", "CDCPAID", "DEDICATED_CLUSTER_PAID"]
storage_state = ["ATTACHED"]
instance_ips = ["10.0.0.2"]
instance_ips = ["10.0.0.2"]
instance_name = ["my-instance"]
tag_keys = ["foo"]
tag_values = ["bar", "baz"]
tag_keys = ["example"]
tag_values = ["bar", "baz"]
portable = true
}
```
43 changes: 35 additions & 8 deletions tencentcloud/services/cbs/data_source_tc_cbs_storages_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func DataSourceTencentCloudCbsStoragesSet() *schema.Resource {
Optional: true,
Description: "The available zone that the CBS instance locates at.",
},
"dedicated_cluster_id": {
Type: schema.TypeString,
Optional: true,
Description: "Exclusive cluster id.",
},
"project_id": {
Type: schema.TypeInt,
Optional: true,
Expand All @@ -51,7 +56,7 @@ func DataSourceTencentCloudCbsStoragesSet() *schema.Resource {
"charge_type": {
Type: schema.TypeList,
Optional: true,
Description: "List filter by disk charge type (`POSTPAID_BY_HOUR` | `PREPAID`).",
Description: "List filter by disk charge type (`POSTPAID_BY_HOUR` | `PREPAID` | `CDCPAID` | `DEDICATED_CLUSTER_PAID`).",
Elem: &schema.Schema{Type: schema.TypeString},
},
"portable": {
Expand Down Expand Up @@ -125,6 +130,11 @@ func DataSourceTencentCloudCbsStoragesSet() *schema.Resource {
Computed: true,
Description: "The zone of CBS.",
},
"dedicated_cluster_id": {
Type: schema.TypeString,
Computed: true,
Description: "Exclusive cluster id.",
},
"project_id": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -188,27 +198,39 @@ func DataSourceTencentCloudCbsStoragesSet() *schema.Resource {
}

func dataSourceTencentCloudCbsStoragesSetRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_cbs_storages.read")()
defer tccommon.LogElapsed("data_source.tencentcloud_cbs_storages_set.read")()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
cbsService = CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
)

params := make(map[string]interface{})
if v, ok := d.GetOk("storage_id"); ok {
params["disk-id"] = v.(string)
}

if v, ok := d.GetOk("storage_name"); ok {
params["disk-name"] = v.(string)
}

if v, ok := d.GetOk("availability_zone"); ok {
params["zone"] = v.(string)
}

if v, ok := d.GetOk("dedicated_cluster_id"); ok {
params["dedicated-cluster-id"] = v.(string)
}

if v, ok := d.GetOkExists("project_id"); ok {
params["project-id"] = fmt.Sprintf("%d", v.(int))
}

if v, ok := d.GetOk("storage_type"); ok {
params["disk-type"] = v.(string)
}

if v, ok := d.GetOk("storage_usage"); ok {
params["disk-usage"] = v.(string)
}
Expand All @@ -228,27 +250,28 @@ func dataSourceTencentCloudCbsStoragesSetRead(d *schema.ResourceData, meta inter
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.(tccommon.ProviderMeta).GetAPIV3Conn(),
}

storages, e := cbsService.DescribeDisksInParallelByFilter(ctx, params)
if e != nil {
return e
}

ids := make([]string, 0, len(storages))
storageList := make([]map[string]interface{}, 0, len(storages))
for _, storage := range storages {
Expand All @@ -258,6 +281,7 @@ func dataSourceTencentCloudCbsStoragesSetRead(d *schema.ResourceData, meta inter
"storage_usage": storage.DiskUsage,
"storage_type": storage.DiskType,
"availability_zone": storage.Placement.Zone,
"dedicated_cluster_id": storage.Placement.DedicatedClusterId,
"project_id": storage.Placement.ProjectId,
"storage_size": storage.DiskSize,
"attached": storage.Attached,
Expand All @@ -269,13 +293,16 @@ func dataSourceTencentCloudCbsStoragesSetRead(d *schema.ResourceData, meta inter
"charge_type": storage.DiskChargeType,
"throughput_performance": storage.ThroughputPerformance,
}

if storage.Tags != nil {
tags := make(map[string]interface{}, len(storage.Tags))
for _, t := range storage.Tags {
tags[*t.Key] = *t.Value
}

mapping["tags"] = tags
}

storageList = append(storageList, mapping)
ids = append(ids, *storage.DiskId)
}
Expand Down
4 changes: 3 additions & 1 deletion tencentcloud/services/cbs/data_source_tc_cbs_storages_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ Use this data source to query detailed information of CBS storages in parallel.

Example Usage

Query CBS by storage set by zone

```hcl
data "tencentcloud_cbs_storages_set" "storages" {
data "tencentcloud_cbs_storages_set" "example" {
availability_zone = "ap-guangzhou-3"
}
```
4 changes: 4 additions & 0 deletions tencentcloud/services/cbs/extension_cbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
CBS_PREPAID_RENEW_FLAG_DISABLE_NOTIFY_AND_MANUAL_RENEW = "DISABLE_NOTIFY_AND_MANUAL_RENEW"
CBS_CHARGE_TYPE_PREPAID = "PREPAID"
CBS_CHARGE_TYPE_POSTPAID = "POSTPAID_BY_HOUR"
CBS_CHARGE_TYPE_CDCPAID = "CDCPAID"
CBS_CHARGE_TYPE_DEDICATED_CLUSTER_PAID = "DEDICATED_CLUSTER_PAID"
)

var CBS_PREPAID_RENEW_FLAG = []string{
Expand All @@ -47,6 +49,8 @@ var CBS_PREPAID_RENEW_FLAG = []string{
var CBS_CHARGE_TYPE = []string{
CBS_CHARGE_TYPE_PREPAID,
CBS_CHARGE_TYPE_POSTPAID,
CBS_CHARGE_TYPE_CDCPAID,
CBS_CHARGE_TYPE_DEDICATED_CLUSTER_PAID,
}

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