Skip to content

feat(as): [123456789] use as for customers #2772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/2772.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/tencentcloud_as_scaling_group: support `health_check_type` and `lb_health_check_grace_period`
```

```release-note:enhancement
resource/tencentcloud_as_lifecycle_hook: support import and parameter `lifecycle_command`
```
61 changes: 58 additions & 3 deletions tencentcloud/services/as/resource_tc_as_lifecycle_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func ResourceTencentCloudAsLifecycleHook() *schema.Resource {
Read: resourceTencentCloudAsLifecycleHookRead,
Update: resourceTencentCloudAsLifecycleHookUpdate,
Delete: resourceTencentCloudAsLifecycleHookDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"scaling_group_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -62,8 +64,8 @@ func ResourceTencentCloudAsLifecycleHook() *schema.Resource {
"notification_target_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"CMQ_QUEUE", "CMQ_TOPIC"}),
Description: "Target type. Valid values: `CMQ_QUEUE`, `CMQ_TOPIC`.",
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"CMQ_QUEUE", "CMQ_TOPIC", "TDMQ_CMQ_QUEUE", "TDMQ_CMQ_TOPIC"}),
Description: "Target type. Valid values: `CMQ_QUEUE`, `CMQ_TOPIC`, `TDMQ_CMQ_QUEUE`, `TDMQ_CMQ_TOPIC`.",
},
"notification_queue_name": {
Type: schema.TypeString,
Expand All @@ -75,6 +77,27 @@ func ResourceTencentCloudAsLifecycleHook() *schema.Resource {
Optional: true,
Description: "For CMQ_TOPIC type, a name of topic must be set.",
},
"lifecycle_command": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Optional: true,
Description: "Remote command execution object. `NotificationTarget` and `LifecycleCommand` cannot be specified at the same time.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"command_id": {
Type: schema.TypeString,
Required: true,
Description: "Remote command ID. It is required to execute a command.",
},
"parameters": {
Type: schema.TypeString,
Optional: true,
Description: "Custom parameter. The field type is JSON encoded string. For example, {\"varA\": \"222\"}.",
},
},
},
},
},
}
}
Expand Down Expand Up @@ -117,6 +140,17 @@ func resourceTencentCloudAsLifecycleHookCreate(d *schema.ResourceData, meta inte
}
}

if dMap, ok := helper.InterfacesHeadMap(d, "lifecycle_command"); ok {
lifecycleCommand := as.LifecycleCommand{}
if v, ok := dMap["command_id"]; ok {
lifecycleCommand.CommandId = helper.String(v.(string))
}
if v, ok := dMap["parameters"]; ok {
lifecycleCommand.Parameters = helper.String(v.(string))
}
request.LifecycleCommand = &lifecycleCommand
}

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",
Expand Down Expand Up @@ -175,6 +209,16 @@ func resourceTencentCloudAsLifecycleHookRead(d *schema.ResourceData, meta interf
_ = d.Set("notification_topic_name", *lifecycleHook.NotificationTarget.TopicName)
}
}
if lifecycleHook.LifecycleCommand != nil {
commandMap := map[string]interface{}{}
if lifecycleHook.LifecycleCommand.CommandId != nil {
commandMap["command_id"] = lifecycleHook.LifecycleCommand.CommandId
}
if lifecycleHook.LifecycleCommand.Parameters != nil {
commandMap["parameters"] = lifecycleHook.LifecycleCommand.Parameters
}
_ = d.Set("lifecycle_command", []interface{}{commandMap})
}
return nil
})
if err != nil {
Expand Down Expand Up @@ -221,6 +265,17 @@ func resourceTencentCloudAsLifecycleHookUpdate(d *schema.ResourceData, meta inte
}
}

if dMap, ok := helper.InterfacesHeadMap(d, "lifecycle_command"); ok {
lifecycleCommand := as.LifecycleCommand{}
if v, ok := dMap["command_id"]; ok {
lifecycleCommand.CommandId = helper.String(v.(string))
}
if v, ok := dMap["parameters"]; ok {
lifecycleCommand.Parameters = helper.String(v.(string))
}
request.LifecycleCommand = &lifecycleCommand
}

response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().UpgradeLifecycleHook(request)
if err != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
Expand Down
36 changes: 30 additions & 6 deletions tencentcloud/services/as/resource_tc_as_lifecycle_hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ resource "tencentcloud_as_scaling_group" "example" {
}

resource "tencentcloud_as_lifecycle_hook" "example" {
scaling_group_id = tencentcloud_as_scaling_group.example.id
lifecycle_hook_name = "tf-as-lifecycle-hook"
lifecycle_transition = "INSTANCE_LAUNCHING"
default_result = "CONTINUE"
heartbeat_timeout = 500
notification_metadata = "tf test"
scaling_group_id = tencentcloud_as_scaling_group.example.id
lifecycle_hook_name = "tf-as-lifecycle-hook"
lifecycle_transition = "INSTANCE_LAUNCHING"
default_result = "CONTINUE"
heartbeat_timeout = 500
notification_metadata = "tf test"
}
```

Expand Down Expand Up @@ -82,4 +82,28 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
notification_target_type = "CMQ_TOPIC"
notification_topic_name = "lifcyclehook"
}
```

Use TAT Command

```hcl
resource "tencentcloud_as_lifecycle_hook" "example" {
default_result = "CONTINUE"
heartbeat_timeout = 300
lifecycle_hook_name = "test"
lifecycle_transition = "INSTANCE_TERMINATING"
scaling_group_id = tencentcloud_as_scaling_group.example.id

lifecycle_command {
command_id = "cmd-xxxx"
}
}
```

Import

lifecycle hook can be imported using the id, e.g.

```
terraform import tencentcloud_as_lifecycle_hook.example lifecycle_hook_id
```
30 changes: 30 additions & 0 deletions tencentcloud/services/as/resource_tc_as_scaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ func ResourceTencentCloudAsScalingGroup() *schema.Resource {
Optional: true,
Description: "Enable unhealthy instance replacement. If set to `true`, AS will replace instances that are found unhealthy in the CLB health check.",
},
"health_check_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
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`.",
},
"lb_health_check_grace_period": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
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`.",
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -294,6 +306,14 @@ func resourceTencentCloudAsScalingGroupCreate(d *schema.ResourceData, meta inter
request.MultiZoneSubnetPolicy = helper.String(v.(string))
}

if v, ok := d.GetOk("health_check_type"); ok {
request.HealthCheckType = helper.String(v.(string))
}

if v, ok := d.GetOkExists("lb_health_check_grace_period"); ok {
request.LoadBalancerHealthCheckGracePeriod = helper.IntUint64(v.(int))
}

var (
scalingMode = d.Get("scaling_mode").(string)
replaceMonitorUnhealthy = d.Get("replace_monitor_unhealthy").(bool)
Expand Down Expand Up @@ -418,6 +438,9 @@ func resourceTencentCloudAsScalingGroupRead(d *schema.ResourceData, meta interfa
_ = d.Set("termination_policies", helper.StringsInterfaces(scalingGroup.TerminationPolicySet))
_ = d.Set("retry_policy", scalingGroup.RetryPolicy)
_ = d.Set("create_time", scalingGroup.CreatedTime)
_ = d.Set("retry_policy", scalingGroup.RetryPolicy)
_ = d.Set("health_check_type", scalingGroup.HealthCheckType)
_ = d.Set("lb_health_check_grace_period", scalingGroup.LoadBalancerHealthCheckGracePeriod)
if v, ok := d.GetOk("multi_zone_subnet_policy"); ok && v.(string) != "" {
_ = d.Set("multi_zone_subnet_policy", scalingGroup.MultiZoneSubnetPolicy)
}
Expand Down Expand Up @@ -568,6 +591,13 @@ func resourceTencentCloudAsScalingGroupUpdate(d *schema.ResourceData, meta inter
}
}

if d.HasChange("health_check_type") || d.HasChange("lb_health_check_grace_period") {
request.HealthCheckType = helper.String(d.Get("health_check_type").(string))
if v, ok := d.GetOkExists("lb_health_check_grace_period"); ok {
request.LoadBalancerHealthCheckGracePeriod = helper.IntUint64(v.(int))
}
}

if err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())

Expand Down
15 changes: 9 additions & 6 deletions tencentcloud/services/as/resource_tc_as_scaling_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ resource "tencentcloud_as_scaling_config" "example" {
}

resource "tencentcloud_as_scaling_group" "example" {
scaling_group_name = "tf-example"
configuration_id = tencentcloud_as_scaling_config.example.id
max_size = 1
min_size = 0
vpc_id = tencentcloud_vpc.vpc.id
subnet_ids = [tencentcloud_subnet.subnet.id]
scaling_group_name = "tf-example"
configuration_id = tencentcloud_as_scaling_config.example.id
max_size = 1
min_size = 0
vpc_id = tencentcloud_vpc.vpc.id
subnet_ids = [tencentcloud_subnet.subnet.id]
health_check_type = "CLB"
replace_load_balancer_unhealthy = true
lb_health_check_grace_period = 30
}
```

Expand Down
32 changes: 31 additions & 1 deletion website/docs/r/as_lifecycle_hook.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ resource "tencentcloud_as_lifecycle_hook" "example" {
}
```

### Use TAT Command

```hcl
resource "tencentcloud_as_lifecycle_hook" "example" {
default_result = "CONTINUE"
heartbeat_timeout = 300
lifecycle_hook_name = "test"
lifecycle_transition = "INSTANCE_TERMINATING"
scaling_group_id = tencentcloud_as_scaling_group.example.id

lifecycle_command {
command_id = "cmd-xxxx"
}
}
```

## Argument Reference

The following arguments are supported:
Expand All @@ -104,11 +120,17 @@ The following arguments are supported:
* `scaling_group_id` - (Required, String, ForceNew) ID of a scaling group.
* `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`.
* `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`.
* `lifecycle_command` - (Optional, List) Remote command execution object. `NotificationTarget` and `LifecycleCommand` cannot be specified at the same time.
* `notification_metadata` - (Optional, String) Contains additional information that you want to include any time AS sends a message to the notification target.
* `notification_queue_name` - (Optional, String) For CMQ_QUEUE type, a name of queue must be set.
* `notification_target_type` - (Optional, String) Target type. Valid values: `CMQ_QUEUE`, `CMQ_TOPIC`.
* `notification_target_type` - (Optional, String) Target type. Valid values: `CMQ_QUEUE`, `CMQ_TOPIC`, `TDMQ_CMQ_QUEUE`, `TDMQ_CMQ_TOPIC`.
* `notification_topic_name` - (Optional, String) For CMQ_TOPIC type, a name of topic must be set.

The `lifecycle_command` object supports the following:

* `command_id` - (Required, String) Remote command ID. It is required to execute a command.
* `parameters` - (Optional, String) Custom parameter. The field type is JSON encoded string. For example, {"varA": "222"}.

## Attributes Reference

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



## Import

lifecycle hook can be imported using the id, e.g.

```
terraform import tencentcloud_as_lifecycle_hook.example lifecycle_hook_id
```

17 changes: 11 additions & 6 deletions website/docs/r/as_scaling_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ resource "tencentcloud_as_scaling_config" "example" {
}

resource "tencentcloud_as_scaling_group" "example" {
scaling_group_name = "tf-example"
configuration_id = tencentcloud_as_scaling_config.example.id
max_size = 1
min_size = 0
vpc_id = tencentcloud_vpc.vpc.id
subnet_ids = [tencentcloud_subnet.subnet.id]
scaling_group_name = "tf-example"
configuration_id = tencentcloud_as_scaling_config.example.id
max_size = 1
min_size = 0
vpc_id = tencentcloud_vpc.vpc.id
subnet_ids = [tencentcloud_subnet.subnet.id]
health_check_type = "CLB"
replace_load_balancer_unhealthy = true
lb_health_check_grace_period = 30
}
```

Expand Down Expand Up @@ -127,6 +130,8 @@ The following arguments are supported:
* `default_cooldown` - (Optional, Int) Default cooldown time in second, and default value is `300`.
* `desired_capacity` - (Optional, Int) Desired volume of CVM instances, which is between `max_size` and `min_size`.
* `forward_balancer_ids` - (Optional, List) List of application load balancers, which can't be specified with `load_balancer_ids` together.
* `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`.
* `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`.
* `load_balancer_ids` - (Optional, List: [`String`]) ID list of traditional load balancers.
* `multi_zone_subnet_policy` - (Optional, String) Multi zone or subnet strategy, Valid values: PRIORITY and EQUALITY.
* `project_id` - (Optional, Int) Specifies to which project the scaling group belongs.
Expand Down
Loading