Skip to content

fix(tag): [122090850] tencentcloud_tag optimize the creation retry logic #3156

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
Feb 26, 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/3156.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_tag: optimize the creation retry logic
```
11 changes: 9 additions & 2 deletions tencentcloud/services/tag/resource_tc_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
tag "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag/v20180813"

"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
Expand All @@ -28,14 +29,14 @@ func ResourceTencentCloudTag() *schema.Resource {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "tag key.",
Description: "Tag key.",
},

"tag_value": {
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: "tag value.",
Description: "Tag value.",
},
},
}
Expand Down Expand Up @@ -65,6 +66,12 @@ func resourceTencentCloudTagResourceCreate(d *schema.ResourceData, meta interfac
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTagClient().CreateTag(request)
if e != nil {
if sdkError, ok := e.(*sdkErrors.TencentCloudSDKError); ok {
if sdkError.Code == "ResourceInUse.TagDuplicate" {
return resource.NonRetryableError(e)
}
}

return tccommon.RetryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
Expand Down
12 changes: 5 additions & 7 deletions tencentcloud/services/tag/resource_tc_tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ Provides a resource to create a tag
Example Usage

```hcl

resource "tencentcloud_tag" "tag" {
tag_key = "test"
tag_value = "Terraform"
resource "tencentcloud_tag" "example" {
tag_key = "tagKey"
tag_value = "tagValue"
}

```

Import

tag tag can be imported using the id, e.g.
tag can be imported using the id, e.g.

```
terraform import tencentcloud_tag.tag tag_id
terraform import tencentcloud_tag.example tagKey#tagValue
```
14 changes: 7 additions & 7 deletions website/docs/r/tag.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ Provides a resource to create a tag
## Example Usage

```hcl
resource "tencentcloud_tag" "tag" {
tag_key = "test"
tag_value = "Terraform"
resource "tencentcloud_tag" "example" {
tag_key = "tagKey"
tag_value = "tagValue"
}
```

## Argument Reference

The following arguments are supported:

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

## Attributes Reference

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

## Import

tag tag can be imported using the id, e.g.
tag can be imported using the id, e.g.

```
terraform import tencentcloud_tag.tag tag_id
terraform import tencentcloud_tag.example tagKey#tagValue
```

Loading