@@ -36,10 +36,10 @@ func DataSourceTencentCloudCbsSnapshots() *schema.Resource {
36
36
Type : schema .TypeString ,
37
37
Optional : true ,
38
38
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` ." ,
40
40
},
41
41
"project_id" : {
42
- Type : schema .TypeInt ,
42
+ Type : schema .TypeString ,
43
43
Optional : true ,
44
44
Description : "ID of the project within the snapshot." ,
45
45
},
@@ -119,38 +119,43 @@ func DataSourceTencentCloudCbsSnapshots() *schema.Resource {
119
119
func dataSourceTencentCloudCbsSnapshotsRead (d * schema.ResourceData , meta interface {}) error {
120
120
defer tccommon .LogElapsed ("data_source.tencentcloud_cbs_snapshots.read" )()
121
121
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
+ )
124
127
125
128
params := make (map [string ]string )
126
129
if v , ok := d .GetOk ("snapshot_id" ); ok {
127
130
params ["snapshot-id" ] = v .(string )
128
131
}
132
+
129
133
if v , ok := d .GetOk ("snapshot_name" ); ok {
130
134
params ["snapshot-name" ] = v .(string )
131
135
}
136
+
132
137
if v , ok := d .GetOk ("storage_id" ); ok {
133
138
params ["disk-id" ] = v .(string )
134
139
}
140
+
135
141
if v , ok := d .GetOk ("storage_usage" ); ok {
136
142
params ["disk-usage" ] = v .(string )
137
143
}
138
- if v , ok := d .GetOkExists ("project_id" ); ok {
144
+
145
+ if v , ok := d .GetOk ("project_id" ); ok {
139
146
params ["project-id" ] = v .(string )
140
147
}
148
+
141
149
if v , ok := d .GetOk ("availability_zone" ); ok {
142
150
params ["zone" ] = v .(string )
143
151
}
144
152
145
- cbsService := CbsService {
146
- client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn (),
147
- }
148
-
149
153
err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
150
154
snapshots , e := cbsService .DescribeSnapshotsByFilter (ctx , params )
151
155
if e != nil {
152
156
return tccommon .RetryError (e )
153
157
}
158
+
154
159
ids := make ([]string , 0 , len (snapshots ))
155
160
snapshotList := make ([]map [string ]interface {}, 0 , len (snapshots ))
156
161
for _ , snapshot := range snapshots {
@@ -166,6 +171,7 @@ func dataSourceTencentCloudCbsSnapshotsRead(d *schema.ResourceData, meta interfa
166
171
"create_time" : * snapshot .CreateTime ,
167
172
"encrypt" : * snapshot .Encrypt ,
168
173
}
174
+
169
175
snapshotList = append (snapshotList , mapping )
170
176
ids = append (ids , * snapshot .SnapshotId )
171
177
}
@@ -185,6 +191,7 @@ func dataSourceTencentCloudCbsSnapshotsRead(d *schema.ResourceData, meta interfa
185
191
186
192
return nil
187
193
})
194
+
188
195
if err != nil {
189
196
log .Printf ("[CRITAL]%s read cbs snapshots failed, reason:%s\n " , logId , err .Error ())
190
197
return err
0 commit comments