Skip to content

Commit 01ff5e3

Browse files
authored
feat(as): [123456789] use as for customers (#2772)
* add user * add changelog * modify doc
1 parent e755577 commit 01ff5e3

7 files changed

+176
-22
lines changed

.changelog/2772.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_as_scaling_group: support `health_check_type` and `lb_health_check_grace_period`
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_as_lifecycle_hook: support import and parameter `lifecycle_command`
7+
```

tencentcloud/services/as/resource_tc_as_lifecycle_hook.go

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ func ResourceTencentCloudAsLifecycleHook() *schema.Resource {
2020
Read: resourceTencentCloudAsLifecycleHookRead,
2121
Update: resourceTencentCloudAsLifecycleHookUpdate,
2222
Delete: resourceTencentCloudAsLifecycleHookDelete,
23-
23+
Importer: &schema.ResourceImporter{
24+
State: schema.ImportStatePassthrough,
25+
},
2426
Schema: map[string]*schema.Schema{
2527
"scaling_group_id": {
2628
Type: schema.TypeString,
@@ -62,8 +64,8 @@ func ResourceTencentCloudAsLifecycleHook() *schema.Resource {
6264
"notification_target_type": {
6365
Type: schema.TypeString,
6466
Optional: true,
65-
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"CMQ_QUEUE", "CMQ_TOPIC"}),
66-
Description: "Target type. Valid values: `CMQ_QUEUE`, `CMQ_TOPIC`.",
67+
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"CMQ_QUEUE", "CMQ_TOPIC", "TDMQ_CMQ_QUEUE", "TDMQ_CMQ_TOPIC"}),
68+
Description: "Target type. Valid values: `CMQ_QUEUE`, `CMQ_TOPIC`, `TDMQ_CMQ_QUEUE`, `TDMQ_CMQ_TOPIC`.",
6769
},
6870
"notification_queue_name": {
6971
Type: schema.TypeString,
@@ -75,6 +77,27 @@ func ResourceTencentCloudAsLifecycleHook() *schema.Resource {
7577
Optional: true,
7678
Description: "For CMQ_TOPIC type, a name of topic must be set.",
7779
},
80+
"lifecycle_command": {
81+
Type: schema.TypeList,
82+
MaxItems: 1,
83+
Computed: true,
84+
Optional: true,
85+
Description: "Remote command execution object. `NotificationTarget` and `LifecycleCommand` cannot be specified at the same time.",
86+
Elem: &schema.Resource{
87+
Schema: map[string]*schema.Schema{
88+
"command_id": {
89+
Type: schema.TypeString,
90+
Required: true,
91+
Description: "Remote command ID. It is required to execute a command.",
92+
},
93+
"parameters": {
94+
Type: schema.TypeString,
95+
Optional: true,
96+
Description: "Custom parameter. The field type is JSON encoded string. For example, {\"varA\": \"222\"}.",
97+
},
98+
},
99+
},
100+
},
78101
},
79102
}
80103
}
@@ -117,6 +140,17 @@ func resourceTencentCloudAsLifecycleHookCreate(d *schema.ResourceData, meta inte
117140
}
118141
}
119142

143+
if dMap, ok := helper.InterfacesHeadMap(d, "lifecycle_command"); ok {
144+
lifecycleCommand := as.LifecycleCommand{}
145+
if v, ok := dMap["command_id"]; ok {
146+
lifecycleCommand.CommandId = helper.String(v.(string))
147+
}
148+
if v, ok := dMap["parameters"]; ok {
149+
lifecycleCommand.Parameters = helper.String(v.(string))
150+
}
151+
request.LifecycleCommand = &lifecycleCommand
152+
}
153+
120154
response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().CreateLifecycleHook(request)
121155
if err != nil {
122156
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
@@ -175,6 +209,16 @@ func resourceTencentCloudAsLifecycleHookRead(d *schema.ResourceData, meta interf
175209
_ = d.Set("notification_topic_name", *lifecycleHook.NotificationTarget.TopicName)
176210
}
177211
}
212+
if lifecycleHook.LifecycleCommand != nil {
213+
commandMap := map[string]interface{}{}
214+
if lifecycleHook.LifecycleCommand.CommandId != nil {
215+
commandMap["command_id"] = lifecycleHook.LifecycleCommand.CommandId
216+
}
217+
if lifecycleHook.LifecycleCommand.Parameters != nil {
218+
commandMap["parameters"] = lifecycleHook.LifecycleCommand.Parameters
219+
}
220+
_ = d.Set("lifecycle_command", []interface{}{commandMap})
221+
}
178222
return nil
179223
})
180224
if err != nil {
@@ -221,6 +265,17 @@ func resourceTencentCloudAsLifecycleHookUpdate(d *schema.ResourceData, meta inte
221265
}
222266
}
223267

268+
if dMap, ok := helper.InterfacesHeadMap(d, "lifecycle_command"); ok {
269+
lifecycleCommand := as.LifecycleCommand{}
270+
if v, ok := dMap["command_id"]; ok {
271+
lifecycleCommand.CommandId = helper.String(v.(string))
272+
}
273+
if v, ok := dMap["parameters"]; ok {
274+
lifecycleCommand.Parameters = helper.String(v.(string))
275+
}
276+
request.LifecycleCommand = &lifecycleCommand
277+
}
278+
224279
response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().UpgradeLifecycleHook(request)
225280
if err != nil {
226281
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",

tencentcloud/services/as/resource_tc_as_lifecycle_hook.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ resource "tencentcloud_as_scaling_group" "example" {
4545
}
4646
4747
resource "tencentcloud_as_lifecycle_hook" "example" {
48-
scaling_group_id = tencentcloud_as_scaling_group.example.id
49-
lifecycle_hook_name = "tf-as-lifecycle-hook"
50-
lifecycle_transition = "INSTANCE_LAUNCHING"
51-
default_result = "CONTINUE"
52-
heartbeat_timeout = 500
53-
notification_metadata = "tf test"
48+
scaling_group_id = tencentcloud_as_scaling_group.example.id
49+
lifecycle_hook_name = "tf-as-lifecycle-hook"
50+
lifecycle_transition = "INSTANCE_LAUNCHING"
51+
default_result = "CONTINUE"
52+
heartbeat_timeout = 500
53+
notification_metadata = "tf test"
5454
}
5555
```
5656

@@ -82,4 +82,28 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
8282
notification_target_type = "CMQ_TOPIC"
8383
notification_topic_name = "lifcyclehook"
8484
}
85+
```
86+
87+
Use TAT Command
88+
89+
```hcl
90+
resource "tencentcloud_as_lifecycle_hook" "example" {
91+
default_result = "CONTINUE"
92+
heartbeat_timeout = 300
93+
lifecycle_hook_name = "test"
94+
lifecycle_transition = "INSTANCE_TERMINATING"
95+
scaling_group_id = tencentcloud_as_scaling_group.example.id
96+
97+
lifecycle_command {
98+
command_id = "cmd-xxxx"
99+
}
100+
}
101+
```
102+
103+
Import
104+
105+
lifecycle hook can be imported using the id, e.g.
106+
107+
```
108+
terraform import tencentcloud_as_lifecycle_hook.example lifecycle_hook_id
85109
```

tencentcloud/services/as/resource_tc_as_scaling_group.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ func ResourceTencentCloudAsScalingGroup() *schema.Resource {
174174
Optional: true,
175175
Description: "Enable unhealthy instance replacement. If set to `true`, AS will replace instances that are found unhealthy in the CLB health check.",
176176
},
177+
"health_check_type": {
178+
Type: schema.TypeString,
179+
Optional: true,
180+
Computed: true,
181+
Description: "Health check type of instances in a scaling group.<br><li>CVM: confirm whether an instance is healthy based on the network status. If the pinged instance is unreachable, the instance will be considered unhealthy. For more information, see [Instance Health Check](https://intl.cloud.tencent.com/document/product/377/8553?from_cn_redirect=1)<br><li>CLB: confirm whether an instance is healthy based on the CLB health check status. For more information, see [Health Check Overview](https://intl.cloud.tencent.com/document/product/214/6097?from_cn_redirect=1).<br>If the parameter is set to `CLB`, the scaling group will check both the network status and the CLB health check status. If the network check indicates unhealthy, the `HealthStatus` field will return `UNHEALTHY`. If the CLB health check indicates unhealthy, the `HealthStatus` field will return `CLB_UNHEALTHY`. If both checks indicate unhealthy, the `HealthStatus` field will return `UNHEALTHY|CLB_UNHEALTHY`. Default value: `CLB`.",
182+
},
183+
"lb_health_check_grace_period": {
184+
Type: schema.TypeInt,
185+
Optional: true,
186+
Computed: true,
187+
Description: "Grace period of the CLB health check during which the `IN_SERVICE` instances added will not be marked as `CLB_UNHEALTHY`.<br>Valid range: 0-7200, in seconds. Default value: `0`.",
188+
},
177189
"tags": {
178190
Type: schema.TypeMap,
179191
Optional: true,
@@ -294,6 +306,14 @@ func resourceTencentCloudAsScalingGroupCreate(d *schema.ResourceData, meta inter
294306
request.MultiZoneSubnetPolicy = helper.String(v.(string))
295307
}
296308

309+
if v, ok := d.GetOk("health_check_type"); ok {
310+
request.HealthCheckType = helper.String(v.(string))
311+
}
312+
313+
if v, ok := d.GetOkExists("lb_health_check_grace_period"); ok {
314+
request.LoadBalancerHealthCheckGracePeriod = helper.IntUint64(v.(int))
315+
}
316+
297317
var (
298318
scalingMode = d.Get("scaling_mode").(string)
299319
replaceMonitorUnhealthy = d.Get("replace_monitor_unhealthy").(bool)
@@ -418,6 +438,9 @@ func resourceTencentCloudAsScalingGroupRead(d *schema.ResourceData, meta interfa
418438
_ = d.Set("termination_policies", helper.StringsInterfaces(scalingGroup.TerminationPolicySet))
419439
_ = d.Set("retry_policy", scalingGroup.RetryPolicy)
420440
_ = d.Set("create_time", scalingGroup.CreatedTime)
441+
_ = d.Set("retry_policy", scalingGroup.RetryPolicy)
442+
_ = d.Set("health_check_type", scalingGroup.HealthCheckType)
443+
_ = d.Set("lb_health_check_grace_period", scalingGroup.LoadBalancerHealthCheckGracePeriod)
421444
if v, ok := d.GetOk("multi_zone_subnet_policy"); ok && v.(string) != "" {
422445
_ = d.Set("multi_zone_subnet_policy", scalingGroup.MultiZoneSubnetPolicy)
423446
}
@@ -568,6 +591,13 @@ func resourceTencentCloudAsScalingGroupUpdate(d *schema.ResourceData, meta inter
568591
}
569592
}
570593

594+
if d.HasChange("health_check_type") || d.HasChange("lb_health_check_grace_period") {
595+
request.HealthCheckType = helper.String(d.Get("health_check_type").(string))
596+
if v, ok := d.GetOkExists("lb_health_check_grace_period"); ok {
597+
request.LoadBalancerHealthCheckGracePeriod = helper.IntUint64(v.(int))
598+
}
599+
}
600+
571601
if err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
572602
ratelimit.Check(request.GetAction())
573603

tencentcloud/services/as/resource_tc_as_scaling_group.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ resource "tencentcloud_as_scaling_config" "example" {
3636
}
3737
3838
resource "tencentcloud_as_scaling_group" "example" {
39-
scaling_group_name = "tf-example"
40-
configuration_id = tencentcloud_as_scaling_config.example.id
41-
max_size = 1
42-
min_size = 0
43-
vpc_id = tencentcloud_vpc.vpc.id
44-
subnet_ids = [tencentcloud_subnet.subnet.id]
39+
scaling_group_name = "tf-example"
40+
configuration_id = tencentcloud_as_scaling_config.example.id
41+
max_size = 1
42+
min_size = 0
43+
vpc_id = tencentcloud_vpc.vpc.id
44+
subnet_ids = [tencentcloud_subnet.subnet.id]
45+
health_check_type = "CLB"
46+
replace_load_balancer_unhealthy = true
47+
lb_health_check_grace_period = 30
4548
}
4649
```
4750

website/docs/r/as_lifecycle_hook.html.markdown

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
9595
}
9696
```
9797

98+
### Use TAT Command
99+
100+
```hcl
101+
resource "tencentcloud_as_lifecycle_hook" "example" {
102+
default_result = "CONTINUE"
103+
heartbeat_timeout = 300
104+
lifecycle_hook_name = "test"
105+
lifecycle_transition = "INSTANCE_TERMINATING"
106+
scaling_group_id = tencentcloud_as_scaling_group.example.id
107+
108+
lifecycle_command {
109+
command_id = "cmd-xxxx"
110+
}
111+
}
112+
```
113+
98114
## Argument Reference
99115

100116
The following arguments are supported:
@@ -104,11 +120,17 @@ The following arguments are supported:
104120
* `scaling_group_id` - (Required, String, ForceNew) ID of a scaling group.
105121
* `default_result` - (Optional, String) Defines the action the AS group should take when the lifecycle hook timeout elapses or if an unexpected failure occurs. Valid values: `CONTINUE` and `ABANDON`. The default value is `CONTINUE`.
106122
* `heartbeat_timeout` - (Optional, Int) Defines the amount of time, in seconds, that can elapse before the lifecycle hook times out. Valid value ranges: (30~7200). and default value is `300`.
123+
* `lifecycle_command` - (Optional, List) Remote command execution object. `NotificationTarget` and `LifecycleCommand` cannot be specified at the same time.
107124
* `notification_metadata` - (Optional, String) Contains additional information that you want to include any time AS sends a message to the notification target.
108125
* `notification_queue_name` - (Optional, String) For CMQ_QUEUE type, a name of queue must be set.
109-
* `notification_target_type` - (Optional, String) Target type. Valid values: `CMQ_QUEUE`, `CMQ_TOPIC`.
126+
* `notification_target_type` - (Optional, String) Target type. Valid values: `CMQ_QUEUE`, `CMQ_TOPIC`, `TDMQ_CMQ_QUEUE`, `TDMQ_CMQ_TOPIC`.
110127
* `notification_topic_name` - (Optional, String) For CMQ_TOPIC type, a name of topic must be set.
111128

129+
The `lifecycle_command` object supports the following:
130+
131+
* `command_id` - (Required, String) Remote command ID. It is required to execute a command.
132+
* `parameters` - (Optional, String) Custom parameter. The field type is JSON encoded string. For example, {"varA": "222"}.
133+
112134
## Attributes Reference
113135

114136
In addition to all arguments above, the following attributes are exported:
@@ -117,3 +139,11 @@ In addition to all arguments above, the following attributes are exported:
117139

118140

119141

142+
## Import
143+
144+
lifecycle hook can be imported using the id, e.g.
145+
146+
```
147+
terraform import tencentcloud_as_lifecycle_hook.example lifecycle_hook_id
148+
```
149+

website/docs/r/as_scaling_group.html.markdown

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ resource "tencentcloud_as_scaling_config" "example" {
4747
}
4848
4949
resource "tencentcloud_as_scaling_group" "example" {
50-
scaling_group_name = "tf-example"
51-
configuration_id = tencentcloud_as_scaling_config.example.id
52-
max_size = 1
53-
min_size = 0
54-
vpc_id = tencentcloud_vpc.vpc.id
55-
subnet_ids = [tencentcloud_subnet.subnet.id]
50+
scaling_group_name = "tf-example"
51+
configuration_id = tencentcloud_as_scaling_config.example.id
52+
max_size = 1
53+
min_size = 0
54+
vpc_id = tencentcloud_vpc.vpc.id
55+
subnet_ids = [tencentcloud_subnet.subnet.id]
56+
health_check_type = "CLB"
57+
replace_load_balancer_unhealthy = true
58+
lb_health_check_grace_period = 30
5659
}
5760
```
5861

@@ -127,6 +130,8 @@ The following arguments are supported:
127130
* `default_cooldown` - (Optional, Int) Default cooldown time in second, and default value is `300`.
128131
* `desired_capacity` - (Optional, Int) Desired volume of CVM instances, which is between `max_size` and `min_size`.
129132
* `forward_balancer_ids` - (Optional, List) List of application load balancers, which can't be specified with `load_balancer_ids` together.
133+
* `health_check_type` - (Optional, String) Health check type of instances in a scaling group.<br><li>CVM: confirm whether an instance is healthy based on the network status. If the pinged instance is unreachable, the instance will be considered unhealthy. For more information, see [Instance Health Check](https://intl.cloud.tencent.com/document/product/377/8553?from_cn_redirect=1)<br><li>CLB: confirm whether an instance is healthy based on the CLB health check status. For more information, see [Health Check Overview](https://intl.cloud.tencent.com/document/product/214/6097?from_cn_redirect=1).<br>If the parameter is set to `CLB`, the scaling group will check both the network status and the CLB health check status. If the network check indicates unhealthy, the `HealthStatus` field will return `UNHEALTHY`. If the CLB health check indicates unhealthy, the `HealthStatus` field will return `CLB_UNHEALTHY`. If both checks indicate unhealthy, the `HealthStatus` field will return `UNHEALTHY|CLB_UNHEALTHY`. Default value: `CLB`.
134+
* `lb_health_check_grace_period` - (Optional, Int) Grace period of the CLB health check during which the `IN_SERVICE` instances added will not be marked as `CLB_UNHEALTHY`.<br>Valid range: 0-7200, in seconds. Default value: `0`.
130135
* `load_balancer_ids` - (Optional, List: [`String`]) ID list of traditional load balancers.
131136
* `multi_zone_subnet_policy` - (Optional, String) Multi zone or subnet strategy, Valid values: PRIORITY and EQUALITY.
132137
* `project_id` - (Optional, Int) Specifies to which project the scaling group belongs.

0 commit comments

Comments
 (0)