@@ -3,8 +3,10 @@ package cbs
3
3
import (
4
4
"context"
5
5
6
+ cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
6
7
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
7
8
9
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8
10
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9
11
10
12
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
@@ -69,14 +71,21 @@ func resourceTencentCloudCbsSnapshotSharePermissionRead(d *schema.ResourceData,
69
71
defer tccommon .InconsistentCheck (d , meta )()
70
72
71
73
logId := tccommon .GetLogId (tccommon .ContextNil )
72
-
73
74
ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
74
-
75
75
service := CbsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
76
-
77
76
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
+ })
78
88
79
- snapshotSharePermissions , err := service .DescribeCbsSnapshotSharePermissionById (ctx , snapshotId )
80
89
if err != nil {
81
90
return err
82
91
}
@@ -99,6 +108,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionUpdate(d *schema.ResourceData
99
108
logId := tccommon .GetLogId (tccommon .ContextNil )
100
109
ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
101
110
service := CbsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
111
+
102
112
if d .HasChange ("account_ids" ) {
103
113
old , new := d .GetChange ("account_ids" )
104
114
oldSet := old .(* schema.Set )
@@ -111,6 +121,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionUpdate(d *schema.ResourceData
111
121
return addError
112
122
}
113
123
}
124
+
114
125
if len (remove ) > 0 {
115
126
removeError := service .ModifySnapshotsSharePermission (ctx , snapshotId , SNAPSHOT_SHARE_PERMISSION_CANCEL , helper .InterfacesStrings (remove ))
116
127
if removeError != nil {
@@ -128,10 +139,20 @@ func resourceTencentCloudCbsSnapshotSharePermissionDelete(d *schema.ResourceData
128
139
129
140
logId := tccommon .GetLogId (tccommon .ContextNil )
130
141
ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
131
-
132
142
service := CbsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
133
143
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
+
135
156
if err != nil {
136
157
return err
137
158
}
@@ -140,6 +161,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionDelete(d *schema.ResourceData
140
161
for _ , snapshotSharePermission := range snapshotSharePermissions {
141
162
accountIds = append (accountIds , * snapshotSharePermission .AccountId )
142
163
}
164
+
143
165
if err := service .ModifySnapshotsSharePermission (ctx , snapshotId , SNAPSHOT_SHARE_PERMISSION_CANCEL , accountIds ); err != nil {
144
166
return err
145
167
}
0 commit comments