Skip to content

Commit 61e7e84

Browse files
authored
fix(cbs): [121657802] tencentcloud_cbs_snapshots update code (#3078)
* add * add * add
1 parent a180ca5 commit 61e7e84

File tree

4 files changed

+81
-15
lines changed

4 files changed

+81
-15
lines changed

.changelog/3078.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
datasource/tencentcloud_cbs_snapshots: update code
3+
```

tencentcloud/services/cbs/data_source_tc_cbs_snapshots.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ func DataSourceTencentCloudCbsSnapshots() *schema.Resource {
3636
Type: schema.TypeString,
3737
Optional: true,
3838
ValidateFunc: tccommon.ValidateAllowedStringValue(CBS_STORAGE_USAGE),
39-
Description: "Types of CBS which this snapshot created from, and available values include SYSTEM_DISK and DATA_DISK.",
39+
Description: "Types of CBS which this snapshot created from, and available values include `SYSTEM_DISK` and `DATA_DISK`.",
4040
},
4141
"project_id": {
42-
Type: schema.TypeInt,
42+
Type: schema.TypeString,
4343
Optional: true,
4444
Description: "ID of the project within the snapshot.",
4545
},
@@ -119,38 +119,43 @@ func DataSourceTencentCloudCbsSnapshots() *schema.Resource {
119119
func dataSourceTencentCloudCbsSnapshotsRead(d *schema.ResourceData, meta interface{}) error {
120120
defer tccommon.LogElapsed("data_source.tencentcloud_cbs_snapshots.read")()
121121

122-
logId := tccommon.GetLogId(tccommon.ContextNil)
123-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
122+
var (
123+
logId = tccommon.GetLogId(tccommon.ContextNil)
124+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
125+
cbsService = CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
126+
)
124127

125128
params := make(map[string]string)
126129
if v, ok := d.GetOk("snapshot_id"); ok {
127130
params["snapshot-id"] = v.(string)
128131
}
132+
129133
if v, ok := d.GetOk("snapshot_name"); ok {
130134
params["snapshot-name"] = v.(string)
131135
}
136+
132137
if v, ok := d.GetOk("storage_id"); ok {
133138
params["disk-id"] = v.(string)
134139
}
140+
135141
if v, ok := d.GetOk("storage_usage"); ok {
136142
params["disk-usage"] = v.(string)
137143
}
138-
if v, ok := d.GetOkExists("project_id"); ok {
144+
145+
if v, ok := d.GetOk("project_id"); ok {
139146
params["project-id"] = v.(string)
140147
}
148+
141149
if v, ok := d.GetOk("availability_zone"); ok {
142150
params["zone"] = v.(string)
143151
}
144152

145-
cbsService := CbsService{
146-
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
147-
}
148-
149153
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
150154
snapshots, e := cbsService.DescribeSnapshotsByFilter(ctx, params)
151155
if e != nil {
152156
return tccommon.RetryError(e)
153157
}
158+
154159
ids := make([]string, 0, len(snapshots))
155160
snapshotList := make([]map[string]interface{}, 0, len(snapshots))
156161
for _, snapshot := range snapshots {
@@ -166,6 +171,7 @@ func dataSourceTencentCloudCbsSnapshotsRead(d *schema.ResourceData, meta interfa
166171
"create_time": *snapshot.CreateTime,
167172
"encrypt": *snapshot.Encrypt,
168173
}
174+
169175
snapshotList = append(snapshotList, mapping)
170176
ids = append(ids, *snapshot.SnapshotId)
171177
}
@@ -185,6 +191,7 @@ func dataSourceTencentCloudCbsSnapshotsRead(d *schema.ResourceData, meta interfa
185191

186192
return nil
187193
})
194+
188195
if err != nil {
189196
log.Printf("[CRITAL]%s read cbs snapshots failed, reason:%s\n ", logId, err.Error())
190197
return err

tencentcloud/services/cbs/data_source_tc_cbs_snapshots.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,37 @@ Use this data source to query detailed information of CBS snapshots.
22

33
Example Usage
44

5+
Query all snapshots
6+
57
```hcl
8+
data "tencentcloud_cbs_snapshots" "snapshots" {}
9+
```
10+
11+
Query snapshots by filters
12+
13+
```hcl
14+
data "tencentcloud_cbs_snapshots" "snapshots" {
15+
snapshot_id = "snap-hibh08s3"
16+
result_output_file = "my_snapshots"
17+
}
18+
19+
data "tencentcloud_cbs_snapshots" "snapshots" {
20+
snapshot_name = "tf-example"
21+
}
22+
23+
data "tencentcloud_cbs_snapshots" "snapshots" {
24+
storage_id = "disk-12j0fk1w"
25+
}
26+
27+
data "tencentcloud_cbs_snapshots" "snapshots" {
28+
storage_usage = "SYSTEM_DISK"
29+
}
30+
31+
data "tencentcloud_cbs_snapshots" "snapshots" {
32+
project_id = "0"
33+
}
34+
635
data "tencentcloud_cbs_snapshots" "snapshots" {
7-
snapshot_id = "snap-f3io7adt"
8-
result_output_file = "mytestpath"
36+
availability_zone = "ap-guangzhou-4"
937
}
1038
```

website/docs/d/cbs_snapshots.html.markdown

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,38 @@ Use this data source to query detailed information of CBS snapshots.
1313

1414
## Example Usage
1515

16+
### Query all snapshots
17+
18+
```hcl
19+
data "tencentcloud_cbs_snapshots" "snapshots" {}
20+
```
21+
22+
### Query snapshots by filters
23+
1624
```hcl
1725
data "tencentcloud_cbs_snapshots" "snapshots" {
18-
snapshot_id = "snap-f3io7adt"
19-
result_output_file = "mytestpath"
26+
snapshot_id = "snap-hibh08s3"
27+
result_output_file = "my_snapshots"
28+
}
29+
30+
data "tencentcloud_cbs_snapshots" "snapshots" {
31+
snapshot_name = "tf-example"
32+
}
33+
34+
data "tencentcloud_cbs_snapshots" "snapshots" {
35+
storage_id = "disk-12j0fk1w"
36+
}
37+
38+
data "tencentcloud_cbs_snapshots" "snapshots" {
39+
storage_usage = "SYSTEM_DISK"
40+
}
41+
42+
data "tencentcloud_cbs_snapshots" "snapshots" {
43+
project_id = "0"
44+
}
45+
46+
data "tencentcloud_cbs_snapshots" "snapshots" {
47+
availability_zone = "ap-guangzhou-4"
2048
}
2149
```
2250

@@ -25,12 +53,12 @@ data "tencentcloud_cbs_snapshots" "snapshots" {
2553
The following arguments are supported:
2654

2755
* `availability_zone` - (Optional, String) The available zone that the CBS instance locates at.
28-
* `project_id` - (Optional, Int) ID of the project within the snapshot.
56+
* `project_id` - (Optional, String) ID of the project within the snapshot.
2957
* `result_output_file` - (Optional, String) Used to save results.
3058
* `snapshot_id` - (Optional, String) ID of the snapshot to be queried.
3159
* `snapshot_name` - (Optional, String) Name of the snapshot to be queried.
3260
* `storage_id` - (Optional, String) ID of the the CBS which this snapshot created from.
33-
* `storage_usage` - (Optional, String) Types of CBS which this snapshot created from, and available values include SYSTEM_DISK and DATA_DISK.
61+
* `storage_usage` - (Optional, String) Types of CBS which this snapshot created from, and available values include `SYSTEM_DISK` and `DATA_DISK`.
3462

3563
## Attributes Reference
3664

0 commit comments

Comments
 (0)