Skip to content

Commit

Permalink
fix(as): [123456789] tencentcloud_as_lifecycle_hook update create f…
Browse files Browse the repository at this point in the history
…unction (#3024)

* add

* add
  • Loading branch information
SevenEarth authored Dec 18, 2024
1 parent ec5072f commit e10ee97
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
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
```

0 comments on commit e10ee97

Please sign in to comment.