@@ -3,8 +3,10 @@ package cbs
33import (
44 "context"
55
6+ cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
67 tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
78
9+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
810 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
911
1012 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
@@ -69,14 +71,21 @@ func resourceTencentCloudCbsSnapshotSharePermissionRead(d *schema.ResourceData,
6971 defer tccommon .InconsistentCheck (d , meta )()
7072
7173 logId := tccommon .GetLogId (tccommon .ContextNil )
72-
7374 ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
74-
7575 service := CbsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
76-
7776 snapshotId := d .Id ()
77+ snapshotSharePermissions := []* cbs.SharePermission {}
78+
79+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
80+ result , e := service .DescribeCbsSnapshotSharePermissionById (ctx , snapshotId )
81+ if e != nil {
82+ return tccommon .RetryError (e )
83+ }
84+
85+ snapshotSharePermissions = result
86+ return nil
87+ })
7888
79- snapshotSharePermissions , err := service .DescribeCbsSnapshotSharePermissionById (ctx , snapshotId )
8089 if err != nil {
8190 return err
8291 }
@@ -99,6 +108,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionUpdate(d *schema.ResourceData
99108 logId := tccommon .GetLogId (tccommon .ContextNil )
100109 ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
101110 service := CbsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
111+
102112 if d .HasChange ("account_ids" ) {
103113 old , new := d .GetChange ("account_ids" )
104114 oldSet := old .(* schema.Set )
@@ -111,6 +121,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionUpdate(d *schema.ResourceData
111121 return addError
112122 }
113123 }
124+
114125 if len (remove ) > 0 {
115126 removeError := service .ModifySnapshotsSharePermission (ctx , snapshotId , SNAPSHOT_SHARE_PERMISSION_CANCEL , helper .InterfacesStrings (remove ))
116127 if removeError != nil {
@@ -128,10 +139,20 @@ func resourceTencentCloudCbsSnapshotSharePermissionDelete(d *schema.ResourceData
128139
129140 logId := tccommon .GetLogId (tccommon .ContextNil )
130141 ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
131-
132142 service := CbsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
133143 snapshotId := d .Id ()
134- snapshotSharePermissions , err := service .DescribeCbsSnapshotSharePermissionById (ctx , snapshotId )
144+ snapshotSharePermissions := []* cbs.SharePermission {}
145+
146+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
147+ result , e := service .DescribeCbsSnapshotSharePermissionById (ctx , snapshotId )
148+ if e != nil {
149+ return tccommon .RetryError (e )
150+ }
151+
152+ snapshotSharePermissions = result
153+ return nil
154+ })
155+
135156 if err != nil {
136157 return err
137158 }
@@ -140,6 +161,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionDelete(d *schema.ResourceData
140161 for _ , snapshotSharePermission := range snapshotSharePermissions {
141162 accountIds = append (accountIds , * snapshotSharePermission .AccountId )
142163 }
164+
143165 if err := service .ModifySnapshotsSharePermission (ctx , snapshotId , SNAPSHOT_SHARE_PERMISSION_CANCEL , accountIds ); err != nil {
144166 return err
145167 }
0 commit comments