Skip to content

Commit a37e6d2

Browse files
authored
fix(tag): [122090850] tencentcloud_tag optimize the creation retry logic (#3156)
* add * add
1 parent 2586e32 commit a37e6d2

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

.changelog/3156.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_tag: optimize the creation retry logic
3+
```

tencentcloud/services/tag/resource_tc_tag.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
13+
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1314
tag "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag/v20180813"
1415

1516
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
@@ -28,14 +29,14 @@ func ResourceTencentCloudTag() *schema.Resource {
2829
Required: true,
2930
ForceNew: true,
3031
Type: schema.TypeString,
31-
Description: "tag key.",
32+
Description: "Tag key.",
3233
},
3334

3435
"tag_value": {
3536
Required: true,
3637
ForceNew: true,
3738
Type: schema.TypeString,
38-
Description: "tag value.",
39+
Description: "Tag value.",
3940
},
4041
},
4142
}
@@ -65,6 +66,12 @@ func resourceTencentCloudTagResourceCreate(d *schema.ResourceData, meta interfac
6566
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
6667
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTagClient().CreateTag(request)
6768
if e != nil {
69+
if sdkError, ok := e.(*sdkErrors.TencentCloudSDKError); ok {
70+
if sdkError.Code == "ResourceInUse.TagDuplicate" {
71+
return resource.NonRetryableError(e)
72+
}
73+
}
74+
6875
return tccommon.RetryError(e)
6976
} else {
7077
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())

tencentcloud/services/tag/resource_tc_tag.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ Provides a resource to create a tag
33
Example Usage
44

55
```hcl
6-
7-
resource "tencentcloud_tag" "tag" {
8-
tag_key = "test"
9-
tag_value = "Terraform"
6+
resource "tencentcloud_tag" "example" {
7+
tag_key = "tagKey"
8+
tag_value = "tagValue"
109
}
11-
1210
```
1311

1412
Import
1513

16-
tag tag can be imported using the id, e.g.
14+
tag can be imported using the id, e.g.
1715

1816
```
19-
terraform import tencentcloud_tag.tag tag_id
17+
terraform import tencentcloud_tag.example tagKey#tagValue
2018
```

website/docs/r/tag.html.markdown

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ Provides a resource to create a tag
1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_tag" "tag" {
18-
tag_key = "test"
19-
tag_value = "Terraform"
17+
resource "tencentcloud_tag" "example" {
18+
tag_key = "tagKey"
19+
tag_value = "tagValue"
2020
}
2121
```
2222

2323
## Argument Reference
2424

2525
The following arguments are supported:
2626

27-
* `tag_key` - (Required, String, ForceNew) tag key.
28-
* `tag_value` - (Required, String, ForceNew) tag value.
27+
* `tag_key` - (Required, String, ForceNew) Tag key.
28+
* `tag_value` - (Required, String, ForceNew) Tag value.
2929

3030
## Attributes Reference
3131

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

3838
## Import
3939

40-
tag tag can be imported using the id, e.g.
40+
tag can be imported using the id, e.g.
4141

4242
```
43-
terraform import tencentcloud_tag.tag tag_id
43+
terraform import tencentcloud_tag.example tagKey#tagValue
4444
```
4545

0 commit comments

Comments
 (0)