Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenEarth committed Dec 18, 2024
1 parent 91b8f2e commit e5c442c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
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 e5c442c

Please sign in to comment.