Skip to content

Commit 601a0fd

Browse files
committed
add
1 parent 13296f2 commit 601a0fd

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed

tencentcloud/services/cbs/resource_tc_cbs_snapshot.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func ResourceTencentCloudCbsSnapshot() *schema.Resource {
4141
"tags": {
4242
Type: schema.TypeMap,
4343
Optional: true,
44-
Deprecated: "cbs snapshot do not support tag now.",
4544
Description: "The available tags within this CBS Snapshot.",
4645
},
4746
"storage_size": {
@@ -81,20 +80,12 @@ func resourceTencentCloudCbsSnapshotCreate(d *schema.ResourceData, meta interfac
8180

8281
storageId := d.Get("storage_id").(string)
8382
snapshotName := d.Get("snapshot_name").(string)
84-
85-
var tags map[string]string
86-
87-
if temp := helper.GetTags(d, "tags"); len(temp) > 0 {
88-
tags = temp
89-
}
90-
cbsService := CbsService{
91-
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
92-
}
83+
cbsService := CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
9384

9485
snapshotId := ""
9586
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
9687
var e error
97-
snapshotId, e = cbsService.CreateSnapshot(ctx, storageId, snapshotName, tags)
88+
snapshotId, e = cbsService.CreateSnapshot(ctx, storageId, snapshotName)
9889
if e != nil {
9990
return tccommon.RetryError(e)
10091
}
@@ -106,15 +97,6 @@ func resourceTencentCloudCbsSnapshotCreate(d *schema.ResourceData, meta interfac
10697
return err
10798
}
10899

109-
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
110-
tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
111-
tagService := svctag.NewTagService(tcClient)
112-
resourceName := tccommon.BuildTagResourceName("cvm", "volume", tcClient.Region, d.Id())
113-
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
114-
return err
115-
}
116-
}
117-
118100
err = resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
119101
snapshot, e := cbsService.DescribeSnapshotById(ctx, snapshotId)
120102
if e != nil {
@@ -136,6 +118,15 @@ func resourceTencentCloudCbsSnapshotCreate(d *schema.ResourceData, meta interfac
136118
return err
137119
}
138120

121+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
122+
tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
123+
tagService := svctag.NewTagService(tcClient)
124+
resourceName := tccommon.BuildTagResourceName("cvm", "volume", tcClient.Region, d.Id())
125+
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
126+
return err
127+
}
128+
}
129+
139130
return resourceTencentCloudCbsSnapshotRead(d, meta)
140131
}
141132

tencentcloud/services/cbs/resource_tc_cbs_snapshot.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ Provides a resource to create a CBS snapshot.
33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_cbs_snapshot" "snapshot" {
7-
snapshot_name = "unnamed"
8-
storage_id = "disk-kdt0sq6m"
6+
resource "tencentcloud_cbs_snapshot" "example" {
7+
snapshot_name = "tf-example"
8+
storage_id = "disk-alc1r5sw"
9+
tags = {
10+
createBy = "Terraform"
11+
}
912
}
1013
```
1114

@@ -14,5 +17,5 @@ Import
1417
CBS snapshot can be imported using the id, e.g.
1518

1619
```
17-
$ terraform import tencentcloud_cbs_snapshot.snapshot snap-3sa3f39b
20+
$ terraform import tencentcloud_cbs_snapshot.example snap-3sa3f39b
1821
```

tencentcloud/services/cbs/service_tencentcloud_cbs.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cbs
22

33
import (
44
"context"
5+
"fmt"
56
"log"
67
"strings"
78
"sync"
@@ -387,20 +388,11 @@ func (me *CbsService) DetachDisk(ctx context.Context, diskId, instanceId string)
387388
return nil
388389
}
389390

390-
func (me *CbsService) CreateSnapshot(ctx context.Context, diskId, snapshotName string, tags map[string]string) (snapshotId string, errRet error) {
391+
func (me *CbsService) CreateSnapshot(ctx context.Context, diskId, snapshotName string) (snapshotId string, errRet error) {
391392
logId := tccommon.GetLogId(ctx)
392393
request := cbs.NewCreateSnapshotRequest()
393394
request.DiskId = &diskId
394395
request.SnapshotName = &snapshotName
395-
if len(tags) > 0 {
396-
for tagKey, tagValue := range tags {
397-
tag := cbs.Tag{
398-
Key: helper.String(tagKey),
399-
Value: helper.String(tagValue),
400-
}
401-
request.Tags = append(request.Tags, &tag)
402-
}
403-
}
404396
ratelimit.Check(request.GetAction())
405397
response, err := me.client.UseCbsClient().CreateSnapshot(request)
406398
if err != nil {
@@ -412,6 +404,11 @@ func (me *CbsService) CreateSnapshot(ctx context.Context, diskId, snapshotName s
412404
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
413405
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
414406

407+
if response == nil || response.Response == nil || response.Response.SnapshotId == nil {
408+
errRet = fmt.Errorf("CreateSnapshot response is nil.")
409+
return
410+
}
411+
415412
snapshotId = *response.Response.SnapshotId
416413
return
417414
}

website/docs/r/cbs_snapshot.html.markdown

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ Provides a resource to create a CBS snapshot.
1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_cbs_snapshot" "snapshot" {
18-
snapshot_name = "unnamed"
19-
storage_id = "disk-kdt0sq6m"
17+
resource "tencentcloud_cbs_snapshot" "example" {
18+
snapshot_name = "tf-example"
19+
storage_id = "disk-alc1r5sw"
20+
tags = {
21+
createBy = "Terraform"
22+
}
2023
}
2124
```
2225

@@ -26,7 +29,7 @@ The following arguments are supported:
2629

2730
* `snapshot_name` - (Required, String) Name of the snapshot.
2831
* `storage_id` - (Required, String, ForceNew) ID of the the CBS which this snapshot created from.
29-
* `tags` - (Optional, Map, **Deprecated**) cbs snapshot do not support tag now. The available tags within this CBS Snapshot.
32+
* `tags` - (Optional, Map) The available tags within this CBS Snapshot.
3033

3134
## Attributes Reference
3235

@@ -45,6 +48,6 @@ In addition to all arguments above, the following attributes are exported:
4548
CBS snapshot can be imported using the id, e.g.
4649

4750
```
48-
$ terraform import tencentcloud_cbs_snapshot.snapshot snap-3sa3f39b
51+
$ terraform import tencentcloud_cbs_snapshot.example snap-3sa3f39b
4952
```
5053

0 commit comments

Comments
 (0)