Skip to content

Commit e5c442c

Browse files
committed
add
1 parent 91b8f2e commit e5c442c

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

tencentcloud/services/as/resource_tc_as_lifecycle_hook.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"strings"
78

89
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1213
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
14+
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1315

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

163-
response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().CreateLifecycleHook(request)
165+
var lifecycleHookId string
166+
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
167+
response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().CreateLifecycleHook(request)
168+
if err != nil {
169+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error())
170+
if e, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
171+
if strings.Contains(e.GetCode(), "LimitExceeded.QuotaNotEnough") {
172+
return resource.RetryableError(err)
173+
}
174+
}
175+
176+
return tccommon.RetryError(err)
177+
}
178+
179+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
180+
if response == nil || response.Response == nil || response.Response.LifecycleHookId == nil {
181+
return resource.NonRetryableError(fmt.Errorf("AS LifecycleHook not exists"))
182+
}
183+
184+
lifecycleHookId = *response.Response.LifecycleHookId
185+
return nil
186+
})
187+
164188
if err != nil {
165-
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
166-
logId, request.GetAction(), request.ToJsonString(), err.Error())
189+
log.Printf("[CRITAL]%s create AS LifecycleHook failed, reason:%s\n", logId, err.Error())
167190
return err
168191
}
169-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
170-
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
171192

172-
if response.Response.LifecycleHookId == nil {
173-
return fmt.Errorf("lifecycle hook id is nil")
174-
}
175-
d.SetId(*response.Response.LifecycleHookId)
193+
d.SetId(lifecycleHookId)
176194

177195
return resourceTencentCloudAsLifecycleHookRead(d, meta)
178196
}

tencentcloud/services/as/resource_tc_as_lifecycle_hook.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
5656
}
5757
```
5858

59-
If `notification_target_type` is `CMQ_QUEUE`
59+
If notification_target_type is CMQ_QUEUE
6060

6161
```hcl
6262
resource "tencentcloud_as_lifecycle_hook" "example" {
@@ -71,7 +71,7 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
7171
}
7272
```
7373

74-
Or `notification_target_type` is `CMQ_TOPIC`
74+
Or notification_target_type is CMQ_TOPIC
7575

7676
```hcl
7777
resource "tencentcloud_as_lifecycle_hook" "example" {
@@ -107,5 +107,5 @@ Import
107107
lifecycle hook can be imported using the id, e.g.
108108

109109
```
110-
terraform import tencentcloud_as_lifecycle_hook.example lifecycle_hook_id
110+
terraform import tencentcloud_as_lifecycle_hook.example ash-ahg67203
111111
```

website/docs/r/as_lifecycle_hook.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
6767
}
6868
```
6969

70-
70+
### If notification_target_type is CMQ_QUEUE
7171

7272
```hcl
7373
resource "tencentcloud_as_lifecycle_hook" "example" {
@@ -82,7 +82,7 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
8282
}
8383
```
8484

85-
85+
### Or notification_target_type is CMQ_TOPIC
8686

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

149149
```
150-
terraform import tencentcloud_as_lifecycle_hook.example lifecycle_hook_id
150+
terraform import tencentcloud_as_lifecycle_hook.example ash-ahg67203
151151
```
152152

0 commit comments

Comments
 (0)