@@ -21,7 +21,6 @@ import (
2121
2222 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
2323 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
24- cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
2524 cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
2625 "github.com/terraform-providers/terraform-provider-tencentcloud/tencentcloud/internal/helper"
2726)
@@ -138,7 +137,7 @@ func dataSourceTencentCloudImages() *schema.Resource {
138137 Description : "Whether support cloud-init." ,
139138 },
140139 "snapshots" : {
141- Type : schema .TypeSet ,
140+ Type : schema .TypeList ,
142141 Computed : true ,
143142 Description : "List of snapshot details." ,
144143 Elem : & schema.Resource {
@@ -311,41 +310,30 @@ func dataSourceTencentCloudImagesRead(d *schema.ResourceData, meta interface{})
311310 return nil
312311}
313312
314- func imagesReadSnapshotByIds (ctx context.Context , cbsService CbsService , image * cvm.Image ) (snapshotResults []map [string ]interface {}, errSnap error ) {
313+ func imagesReadSnapshotByIds (ctx context.Context , cbsService CbsService , image * cvm.Image ) (snapshotResults []map [string ]interface {}, errRet error ) {
315314 if len (image .SnapshotSet ) == 0 {
316315 return
317316 }
318317
319- snapshotSetMap := map [string ]interface {}{}
320318 snapshotByIds := make ([]* string , 0 , len (image .SnapshotSet ))
321319 for _ , snapshot := range image .SnapshotSet {
322320 snapshotByIds = append (snapshotByIds , snapshot .SnapshotId )
323321 }
324322
325- snapshots , errSnap := cbsService .DescribeSnapshotByIds (ctx , snapshotByIds )
326- if errSnap != nil {
323+ snapshots , errRet := cbsService .DescribeSnapshotByIds (ctx , snapshotByIds )
324+ if errRet != nil {
327325 return
328326 }
329327
328+ snapshotResults = make ([]map [string ]interface {}, 0 , len (snapshots ))
330329 for _ , snapshot := range snapshots {
331- snapshotSetMap [* snapshot .SnapshotId ] = snapshot
332- }
333-
334- snapshotSet := image .SnapshotSet
335- snapshotResults = make ([]map [string ]interface {}, 0 , len (snapshotSet ))
336- if len (snapshotSet ) > 0 {
337- for _ , snapshot := range snapshotSet {
338- snapshotMap := make (map [string ]interface {}, 4 )
339- id := snapshot .SnapshotId
340- snapshotMap ["snapshot_id" ] = * id
341- snapshotMap ["disk_usage" ] = snapshot .DiskUsage
342- snapshotMap ["disk_size" ] = snapshot .DiskSize
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
343335
344- if v , ok := snapshotSetMap [* id ]; ok {
345- snapshotMap ["snapshot_name" ] = v .(* cbs.Snapshot ).SnapshotName
346- }
347- snapshotResults = append (snapshotResults , snapshotMap )
348- }
336+ snapshotResults = append (snapshotResults , snapshotMap )
349337 }
350338
351339 return
0 commit comments