Skip to content

fix(cbs): [140011685] tencentcloud_cbs_snapshot_share_permission update code and doc #3263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3263.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cbs_snapshot_share_permission: update code and doc
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package cbs
import (
"context"

cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
Expand Down Expand Up @@ -69,14 +71,21 @@ func resourceTencentCloudCbsSnapshotSharePermissionRead(d *schema.ResourceData,
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)

ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

service := CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

snapshotId := d.Id()
snapshotSharePermissions := []*cbs.SharePermission{}

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCbsSnapshotSharePermissionById(ctx, snapshotId)
if e != nil {
return tccommon.RetryError(e)
}

snapshotSharePermissions = result
return nil
})

snapshotSharePermissions, err := service.DescribeCbsSnapshotSharePermissionById(ctx, snapshotId)
if err != nil {
return err
}
Expand All @@ -99,6 +108,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionUpdate(d *schema.ResourceData
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service := CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

if d.HasChange("account_ids") {
old, new := d.GetChange("account_ids")
oldSet := old.(*schema.Set)
Expand All @@ -111,6 +121,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionUpdate(d *schema.ResourceData
return addError
}
}

if len(remove) > 0 {
removeError := service.ModifySnapshotsSharePermission(ctx, snapshotId, SNAPSHOT_SHARE_PERMISSION_CANCEL, helper.InterfacesStrings(remove))
if removeError != nil {
Expand All @@ -128,10 +139,20 @@ func resourceTencentCloudCbsSnapshotSharePermissionDelete(d *schema.ResourceData

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

service := CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
snapshotId := d.Id()
snapshotSharePermissions, err := service.DescribeCbsSnapshotSharePermissionById(ctx, snapshotId)
snapshotSharePermissions := []*cbs.SharePermission{}

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCbsSnapshotSharePermissionById(ctx, snapshotId)
if e != nil {
return tccommon.RetryError(e)
}

snapshotSharePermissions = result
return nil
})

if err != nil {
return err
}
Expand All @@ -140,6 +161,7 @@ func resourceTencentCloudCbsSnapshotSharePermissionDelete(d *schema.ResourceData
for _, snapshotSharePermission := range snapshotSharePermissions {
accountIds = append(accountIds, *snapshotSharePermission.AccountId)
}

if err := service.ModifySnapshotsSharePermission(ctx, snapshotId, SNAPSHOT_SHARE_PERMISSION_CANCEL, accountIds); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Provides a resource to create a cbs snapshot_share_permission
Provides a resource to create a CBS snapshot share permission

Example Usage

```hcl
resource "tencentcloud_cbs_snapshot_share_permission" "snapshot_share_permission" {
account_ids = ["1xxxxxx", "2xxxxxx"]
snapshot_id = "snap-xxxxxx"
resource "tencentcloud_cbs_snapshot_share_permission" "example" {
account_ids = ["10002320****", "10002277****"]
snapshot_id = "snap-cs5kj0j8"
}
```

Import

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

```
terraform import tencentcloud_cbs_snapshot_share_permission.snapshot_share_permission snap-xxxxxx
```
terraform import tencentcloud_cbs_snapshot_share_permission.example snap-cs5kj0j8
```
10 changes: 9 additions & 1 deletion tencentcloud/services/cbs/resource_tc_cbs_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,15 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
return err
}
if v, ok := d.GetOk("disk_backup_quota"); ok {
err = cbsService.ModifyDiskBackupQuota(ctx, storageId, v.(int))
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
e := cbsService.ModifyDiskBackupQuota(ctx, storageId, v.(int))
if e != nil {
return tccommon.RetryError(e, tccommon.InternalError)
}

return nil
})

if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions website/docs/r/cbs_snapshot_share_permission.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ layout: "tencentcloud"
page_title: "TencentCloud: tencentcloud_cbs_snapshot_share_permission"
sidebar_current: "docs-tencentcloud-resource-cbs_snapshot_share_permission"
description: |-
Provides a resource to create a cbs snapshot_share_permission
Provides a resource to create a CBS snapshot share permission
---

# tencentcloud_cbs_snapshot_share_permission

Provides a resource to create a cbs snapshot_share_permission
Provides a resource to create a CBS snapshot share permission

## Example Usage

```hcl
resource "tencentcloud_cbs_snapshot_share_permission" "snapshot_share_permission" {
account_ids = ["1xxxxxx", "2xxxxxx"]
snapshot_id = "snap-xxxxxx"
resource "tencentcloud_cbs_snapshot_share_permission" "example" {
account_ids = ["10002320****", "10002277****"]
snapshot_id = "snap-cs5kj0j8"
}
```

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

## Import

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

```
terraform import tencentcloud_cbs_snapshot_share_permission.snapshot_share_permission snap-xxxxxx
terraform import tencentcloud_cbs_snapshot_share_permission.example snap-cs5kj0j8
```

Loading