Skip to content

Commit 44a9cc5

Browse files
authored
fix(cbs): [140011685] tencentcloud_cbs_snapshot_share_permission update code and doc (#3263)
* add * add
1 parent 1120944 commit 44a9cc5

5 files changed

+54
-21
lines changed

.changelog/3263.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_cbs_snapshot_share_permission: update code and doc
3+
```

tencentcloud/services/cbs/resource_tc_cbs_snapshot_share_permission.go

+28-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package cbs
33
import (
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
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
Provides a resource to create a cbs snapshot_share_permission
1+
Provides a resource to create a CBS snapshot share permission
22

33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_cbs_snapshot_share_permission" "snapshot_share_permission" {
7-
account_ids = ["1xxxxxx", "2xxxxxx"]
8-
snapshot_id = "snap-xxxxxx"
6+
resource "tencentcloud_cbs_snapshot_share_permission" "example" {
7+
account_ids = ["10002320****", "10002277****"]
8+
snapshot_id = "snap-cs5kj0j8"
99
}
1010
```
1111

1212
Import
1313

14-
cbs snapshot_share_permission can be imported using the id, e.g.
14+
CBS snapshot share permission can be imported using the id, e.g.
1515

1616
```
17-
terraform import tencentcloud_cbs_snapshot_share_permission.snapshot_share_permission snap-xxxxxx
18-
```
17+
terraform import tencentcloud_cbs_snapshot_share_permission.example snap-cs5kj0j8
18+
```

tencentcloud/services/cbs/resource_tc_cbs_storage.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,15 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
248248
return err
249249
}
250250
if v, ok := d.GetOk("disk_backup_quota"); ok {
251-
err = cbsService.ModifyDiskBackupQuota(ctx, storageId, v.(int))
251+
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
252+
e := cbsService.ModifyDiskBackupQuota(ctx, storageId, v.(int))
253+
if e != nil {
254+
return tccommon.RetryError(e, tccommon.InternalError)
255+
}
256+
257+
return nil
258+
})
259+
252260
if err != nil {
253261
return err
254262
}

website/docs/r/cbs_snapshot_share_permission.html.markdown

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ layout: "tencentcloud"
44
page_title: "TencentCloud: tencentcloud_cbs_snapshot_share_permission"
55
sidebar_current: "docs-tencentcloud-resource-cbs_snapshot_share_permission"
66
description: |-
7-
Provides a resource to create a cbs snapshot_share_permission
7+
Provides a resource to create a CBS snapshot share permission
88
---
99

1010
# tencentcloud_cbs_snapshot_share_permission
1111

12-
Provides a resource to create a cbs snapshot_share_permission
12+
Provides a resource to create a CBS snapshot share permission
1313

1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_cbs_snapshot_share_permission" "snapshot_share_permission" {
18-
account_ids = ["1xxxxxx", "2xxxxxx"]
19-
snapshot_id = "snap-xxxxxx"
17+
resource "tencentcloud_cbs_snapshot_share_permission" "example" {
18+
account_ids = ["10002320****", "10002277****"]
19+
snapshot_id = "snap-cs5kj0j8"
2020
}
2121
```
2222

@@ -37,9 +37,9 @@ In addition to all arguments above, the following attributes are exported:
3737

3838
## Import
3939

40-
cbs snapshot_share_permission can be imported using the id, e.g.
40+
CBS snapshot share permission can be imported using the id, e.g.
4141

4242
```
43-
terraform import tencentcloud_cbs_snapshot_share_permission.snapshot_share_permission snap-xxxxxx
43+
terraform import tencentcloud_cbs_snapshot_share_permission.example snap-cs5kj0j8
4444
```
4545

0 commit comments

Comments
 (0)