Skip to content

Commit 2b7821b

Browse files
authored
support complete lifecyle action (#1937)
* support complete lifecyle action * add changelog
1 parent d1a6f8c commit 2b7821b

File tree

6 files changed

+203
-0
lines changed

6 files changed

+203
-0
lines changed

.changelog/1937.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_as_complete_lifecycle
3+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Auto Scaling(AS)
151151
tencentcloud_as_scale_in_instances
152152
tencentcloud_as_scale_out_instances
153153
tencentcloud_as_execute_scaling_policy
154+
tencentcloud_as_complete_lifecycle
154155
155156
Content Delivery Network(CDN)
156157
Data Source
@@ -2390,6 +2391,7 @@ func Provider() *schema.Provider {
23902391
"tencentcloud_as_scale_in_instances": resourceTencentCloudAsScaleInInstances(),
23912392
"tencentcloud_as_scale_out_instances": resourceTencentCloudAsScaleOutInstances(),
23922393
"tencentcloud_as_execute_scaling_policy": resourceTencentCloudAsExecuteScalingPolicy(),
2394+
"tencentcloud_as_complete_lifecycle": resourceTencentCloudAsCompleteLifecycle(),
23932395
"tencentcloud_mongodb_instance": resourceTencentCloudMongodbInstance(),
23942396
"tencentcloud_mongodb_sharding_instance": resourceTencentCloudMongodbShardingInstance(),
23952397
"tencentcloud_mongodb_instance_account": resourceTencentCloudMongodbInstanceAccount(),
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
Provides a resource to create a as complete_lifecycle
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_as_complete_lifecycle" "complete_lifecycle" {
8+
lifecycle_hook_id = "ash-xxxxxxxx"
9+
lifecycle_action_result = "CONTINUE"
10+
instance_id = "ins-xxxxxxxx"
11+
}
12+
```
13+
*/
14+
package tencentcloud
15+
16+
import (
17+
"log"
18+
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
21+
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
22+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
23+
)
24+
25+
func resourceTencentCloudAsCompleteLifecycle() *schema.Resource {
26+
return &schema.Resource{
27+
Create: resourceTencentCloudAsCompleteLifecycleCreate,
28+
Read: resourceTencentCloudAsCompleteLifecycleRead,
29+
Delete: resourceTencentCloudAsCompleteLifecycleDelete,
30+
Importer: &schema.ResourceImporter{
31+
State: schema.ImportStatePassthrough,
32+
},
33+
Schema: map[string]*schema.Schema{
34+
"lifecycle_hook_id": {
35+
Required: true,
36+
ForceNew: true,
37+
Type: schema.TypeString,
38+
Description: "Lifecycle hook ID.",
39+
},
40+
41+
"lifecycle_action_result": {
42+
Required: true,
43+
ForceNew: true,
44+
Type: schema.TypeString,
45+
Description: "Result of the lifecycle action. Value range: `CONTINUE`, `ABANDON`.",
46+
},
47+
48+
"instance_id": {
49+
Optional: true,
50+
ForceNew: true,
51+
Type: schema.TypeString,
52+
Description: "Instance ID. Either InstanceId or LifecycleActionToken must be specified.",
53+
},
54+
55+
"lifecycle_action_token": {
56+
Optional: true,
57+
ForceNew: true,
58+
Type: schema.TypeString,
59+
Description: "Either InstanceId or LifecycleActionToken must be specified.",
60+
},
61+
},
62+
}
63+
}
64+
65+
func resourceTencentCloudAsCompleteLifecycleCreate(d *schema.ResourceData, meta interface{}) error {
66+
defer logElapsed("resource.tencentcloud_as_complete_lifecycle.create")()
67+
defer inconsistentCheck(d, meta)()
68+
69+
logId := getLogId(contextNil)
70+
71+
var (
72+
request = as.NewCompleteLifecycleActionRequest()
73+
lifecycleHookId string
74+
)
75+
if v, ok := d.GetOk("lifecycle_hook_id"); ok {
76+
lifecycleHookId = v.(string)
77+
request.LifecycleHookId = helper.String(v.(string))
78+
}
79+
80+
if v, ok := d.GetOk("lifecycle_action_result"); ok {
81+
request.LifecycleActionResult = helper.String(v.(string))
82+
}
83+
84+
if v, ok := d.GetOk("instance_id"); ok {
85+
request.InstanceId = helper.String(v.(string))
86+
}
87+
88+
if v, ok := d.GetOk("lifecycle_action_token"); ok {
89+
request.LifecycleActionToken = helper.String(v.(string))
90+
}
91+
92+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
93+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseAsClient().CompleteLifecycleAction(request)
94+
if e != nil {
95+
return retryError(e)
96+
} else {
97+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
98+
}
99+
return nil
100+
})
101+
if err != nil {
102+
log.Printf("[CRITAL]%s operate as completeLifecycle failed, reason:%+v", logId, err)
103+
return err
104+
}
105+
106+
d.SetId(lifecycleHookId)
107+
108+
return resourceTencentCloudAsCompleteLifecycleRead(d, meta)
109+
}
110+
111+
func resourceTencentCloudAsCompleteLifecycleRead(d *schema.ResourceData, meta interface{}) error {
112+
defer logElapsed("resource.tencentcloud_as_complete_lifecycle.read")()
113+
defer inconsistentCheck(d, meta)()
114+
115+
return nil
116+
}
117+
118+
func resourceTencentCloudAsCompleteLifecycleDelete(d *schema.ResourceData, meta interface{}) error {
119+
defer logElapsed("resource.tencentcloud_as_complete_lifecycle.delete")()
120+
defer inconsistentCheck(d, meta)()
121+
122+
return nil
123+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudNeedFixAsCompleteLifecycleResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccAsCompleteLifecycle,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_as_complete_lifecycle.complete_lifecycle", "id")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccAsCompleteLifecycle = `
26+
27+
resource "tencentcloud_as_complete_lifecycle" "complete_lifecycle" {
28+
lifecycle_hook_id = "ash-xxxxxxxx"
29+
lifecycle_action_result = "CONTINUE"
30+
instance_id = "ins-xxxxxxxx"
31+
}
32+
`
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
subcategory: "Auto Scaling(AS)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_as_complete_lifecycle"
5+
sidebar_current: "docs-tencentcloud-resource-as_complete_lifecycle"
6+
description: |-
7+
Provides a resource to create a as complete_lifecycle
8+
---
9+
10+
# tencentcloud_as_complete_lifecycle
11+
12+
Provides a resource to create a as complete_lifecycle
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_as_complete_lifecycle" "complete_lifecycle" {
18+
lifecycle_hook_id = "ash-xxxxxxxx"
19+
lifecycle_action_result = "CONTINUE"
20+
instance_id = "ins-xxxxxxxx"
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `lifecycle_action_result` - (Required, String, ForceNew) Result of the lifecycle action. Value range: `CONTINUE`, `ABANDON`.
29+
* `lifecycle_hook_id` - (Required, String, ForceNew) Lifecycle hook ID.
30+
* `instance_id` - (Optional, String, ForceNew) Instance ID. Either InstanceId or LifecycleActionToken must be specified.
31+
* `lifecycle_action_token` - (Optional, String, ForceNew) Either InstanceId or LifecycleActionToken must be specified.
32+
33+
## Attributes Reference
34+
35+
In addition to all arguments above, the following attributes are exported:
36+
37+
* `id` - ID of the resource.
38+
39+
40+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@
262262
<li>
263263
<a href="/docs/providers/tencentcloud/r/as_attachment.html">tencentcloud_as_attachment</a>
264264
</li>
265+
<li>
266+
<a href="/docs/providers/tencentcloud/r/as_complete_lifecycle.html">tencentcloud_as_complete_lifecycle</a>
267+
</li>
265268
<li>
266269
<a href="/docs/providers/tencentcloud/r/as_execute_scaling_policy.html">tencentcloud_as_execute_scaling_policy</a>
267270
</li>

0 commit comments

Comments
 (0)