@@ -136,6 +136,35 @@ func dataSourceTencentCloudImages() *schema.Resource {
136136 Computed : true ,
137137 Description : "Whether support cloud-init." ,
138138 },
139+ "snapshots" : {
140+ Type : schema .TypeList ,
141+ Computed : true ,
142+ Description : "List of snapshot details." ,
143+ Elem : & schema.Resource {
144+ Schema : map [string ]* schema.Schema {
145+ "snapshot_id" : {
146+ Type : schema .TypeString ,
147+ Computed : true ,
148+ Description : "Snapshot ID." ,
149+ },
150+ "snapshot_name" : {
151+ Type : schema .TypeString ,
152+ Computed : true ,
153+ Description : "Snapshot name, the user-defined snapshot alias." ,
154+ },
155+ "disk_usage" : {
156+ Type : schema .TypeString ,
157+ Computed : true ,
158+ Description : "Type of the cloud disk used to create the snapshot." ,
159+ },
160+ "disk_size" : {
161+ Type : schema .TypeInt ,
162+ Computed : true ,
163+ Description : "Size of the cloud disk used to create the snapshot; unit: GB." ,
164+ },
165+ },
166+ },
167+ },
139168 },
140169 },
141170 },
@@ -153,6 +182,10 @@ func dataSourceTencentCloudImagesRead(d *schema.ResourceData, meta interface{})
153182 client : meta .(* TencentCloudClient ).apiV3Conn ,
154183 }
155184
185+ cbsService := CbsService {
186+ client : meta .(* TencentCloudClient ).apiV3Conn ,
187+ }
188+
156189 var (
157190 imageId string
158191 imageType []string
@@ -234,6 +267,11 @@ func dataSourceTencentCloudImagesRead(d *schema.ResourceData, meta interface{})
234267 imageList := make ([]map [string ]interface {}, 0 , len (results ))
235268 ids := make ([]string , 0 , len (results ))
236269 for _ , image := range results {
270+ snapshots , err := imagesReadSnapshotByIds (ctx , cbsService , image )
271+ if err != nil {
272+ return err
273+ }
274+
237275 mapping := map [string ]interface {}{
238276 "image_id" : image .ImageId ,
239277 "os_name" : image .OsName ,
@@ -249,6 +287,7 @@ func dataSourceTencentCloudImagesRead(d *schema.ResourceData, meta interface{})
249287 "image_source" : image .ImageSource ,
250288 "sync_percent" : image .SyncPercent ,
251289 "support_cloud_init" : image .IsSupportCloudinit ,
290+ "snapshots" : snapshots ,
252291 }
253292 imageList = append (imageList , mapping )
254293 ids = append (ids , * image .ImageId )
@@ -270,3 +309,32 @@ func dataSourceTencentCloudImagesRead(d *schema.ResourceData, meta interface{})
270309
271310 return nil
272311}
312+
313+ func imagesReadSnapshotByIds (ctx context.Context , cbsService CbsService , image * cvm.Image ) (snapshotResults []map [string ]interface {}, errRet error ) {
314+ if len (image .SnapshotSet ) == 0 {
315+ return
316+ }
317+
318+ snapshotByIds := make ([]* string , 0 , len (image .SnapshotSet ))
319+ for _ , snapshot := range image .SnapshotSet {
320+ snapshotByIds = append (snapshotByIds , snapshot .SnapshotId )
321+ }
322+
323+ snapshots , errRet := cbsService .DescribeSnapshotByIds (ctx , snapshotByIds )
324+ if errRet != nil {
325+ return
326+ }
327+
328+ snapshotResults = make ([]map [string ]interface {}, 0 , len (snapshots ))
329+ for _ , snapshot := range snapshots {
330+ snapshotMap := make (map [string ]interface {}, 4 )
331+ snapshotMap ["snapshot_id" ] = snapshot .SnapshotId
332+ snapshotMap ["disk_usage" ] = snapshot .DiskUsage
333+ snapshotMap ["disk_size" ] = snapshot .DiskSize
334+ snapshotMap ["snapshot_name" ] = snapshot .SnapshotName
335+
336+ snapshotResults = append (snapshotResults , snapshotMap )
337+ }
338+
339+ return
340+ }
0 commit comments