Skip to content

fix(as): [123456789] tencentcloud_as_lifecycle_hook update create function #3024

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
Dec 18, 2024
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/3024.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_as_lifecycle_hook: update create function
```
36 changes: 27 additions & 9 deletions tencentcloud/services/as/resource_tc_as_lifecycle_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"fmt"
"log"
"strings"

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"
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"

"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
Expand Down Expand Up @@ -160,19 +162,35 @@ func resourceTencentCloudAsLifecycleHookCreate(d *schema.ResourceData, meta inte
request.LifecycleCommand = &lifecycleCommand
}

response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().CreateLifecycleHook(request)
var lifecycleHookId string
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().CreateLifecycleHook(request)
if err != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error())
if e, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
if strings.Contains(e.GetCode(), "LimitExceeded.QuotaNotEnough") {
return resource.RetryableError(err)
}
}

return tccommon.RetryError(err)
}

log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
if response == nil || response.Response == nil || response.Response.LifecycleHookId == nil {
return resource.NonRetryableError(fmt.Errorf("AS LifecycleHook not exists"))
}

lifecycleHookId = *response.Response.LifecycleHookId
return nil
})

if err != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
logId, request.GetAction(), request.ToJsonString(), err.Error())
log.Printf("[CRITAL]%s create AS LifecycleHook failed, reason:%s\n", logId, err.Error())
return err
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if response.Response.LifecycleHookId == nil {
return fmt.Errorf("lifecycle hook id is nil")
}
d.SetId(*response.Response.LifecycleHookId)
d.SetId(lifecycleHookId)

return resourceTencentCloudAsLifecycleHookRead(d, meta)
}
Expand Down
6 changes: 3 additions & 3 deletions tencentcloud/services/as/resource_tc_as_lifecycle_hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
}
```

If `notification_target_type` is `CMQ_QUEUE`
If notification_target_type is CMQ_QUEUE

```hcl
resource "tencentcloud_as_lifecycle_hook" "example" {
Expand All @@ -71,7 +71,7 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
}
```

Or `notification_target_type` is `CMQ_TOPIC`
Or notification_target_type is CMQ_TOPIC

```hcl
resource "tencentcloud_as_lifecycle_hook" "example" {
Expand Down Expand Up @@ -107,5 +107,5 @@ Import
lifecycle hook can be imported using the id, e.g.

```
terraform import tencentcloud_as_lifecycle_hook.example lifecycle_hook_id
terraform import tencentcloud_as_lifecycle_hook.example ash-ahg67203
```
6 changes: 3 additions & 3 deletions website/docs/r/as_lifecycle_hook.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
}
```


### If notification_target_type is CMQ_QUEUE

```hcl
resource "tencentcloud_as_lifecycle_hook" "example" {
Expand All @@ -82,7 +82,7 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
}
```


### Or notification_target_type is CMQ_TOPIC

```hcl
resource "tencentcloud_as_lifecycle_hook" "example" {
Expand Down Expand Up @@ -147,6 +147,6 @@ In addition to all arguments above, the following attributes are exported:
lifecycle hook can be imported using the id, e.g.

```
terraform import tencentcloud_as_lifecycle_hook.example lifecycle_hook_id
terraform import tencentcloud_as_lifecycle_hook.example ash-ahg67203
```

Loading