Skip to content

feat(tke): [119722168] add lifecycle_transition_type #2943

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
Nov 6, 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
3 changes: 3 additions & 0 deletions .changelog/2943.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_as_lifecycle_hook: add `lifecycle_transition_type`
```
33 changes: 25 additions & 8 deletions tencentcloud/services/as/resource_tc_as_lifecycle_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func ResourceTencentCloudAsLifecycleHook() *schema.Resource {
Optional: true,
Description: "For CMQ_TOPIC type, a name of topic must be set.",
},
"lifecycle_transition_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The scenario where the lifecycle hook is applied. `EXTENSION`: the lifecycle hook will be triggered when AttachInstances, DetachInstances or RemoveInstaces is called. `NORMAL`: the lifecycle hook is not triggered by the above APIs.",
},
"lifecycle_command": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -122,6 +128,9 @@ func resourceTencentCloudAsLifecycleHookCreate(d *schema.ResourceData, meta inte
if v, ok := d.GetOk("notification_metadata"); ok {
request.NotificationMetadata = helper.String(v.(string))
}
if v, ok := d.GetOk("lifecycle_transition_type"); ok {
request.LifecycleTransitionType = helper.String(v.(string))
}
if v, ok := d.GetOk("notification_target_type"); ok {
request.NotificationTarget = &as.NotificationTarget{}
request.NotificationTarget.TargetType = helper.String(v.(string))
Expand Down Expand Up @@ -200,6 +209,9 @@ func resourceTencentCloudAsLifecycleHookRead(d *schema.ResourceData, meta interf
if lifecycleHook.NotificationMetadata != nil {
_ = d.Set("notification_metadata", *lifecycleHook.NotificationMetadata)
}
if lifecycleHook.LifecycleTransitionType != nil {
_ = d.Set("lifecycle_transition_type", *lifecycleHook.LifecycleTransitionType)
}
if lifecycleHook.NotificationTarget != nil {
_ = d.Set("notification_target_type", *lifecycleHook.NotificationTarget.TargetType)
if lifecycleHook.NotificationTarget.QueueName != nil {
Expand Down Expand Up @@ -247,6 +259,9 @@ func resourceTencentCloudAsLifecycleHookUpdate(d *schema.ResourceData, meta inte
if v, ok := d.GetOk("notification_metadata"); ok {
request.NotificationMetadata = helper.String(v.(string))
}
if v, ok := d.GetOk("lifecycle_transition_type"); ok {
request.LifecycleTransitionType = helper.String(v.(string))
}
if v, ok := d.GetOk("notification_target_type"); ok {
request.NotificationTarget = &as.NotificationTarget{}
request.NotificationTarget.TargetType = helper.String(v.(string))
Expand All @@ -265,15 +280,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))
if d.HasChange("lifecycle_command") {
if dMap, ok := helper.InterfacesHeadMap(d, "lifecycle_command"); ok {
lifecycleCommand := as.LifecycleCommand{}
if v, ok := dMap["command_id"]; ok && v != "" {
lifecycleCommand.CommandId = helper.String(v.(string))
}
if v, ok := dMap["parameters"]; ok && v != "" {
lifecycleCommand.Parameters = helper.String(v.(string))
}
request.LifecycleCommand = &lifecycleCommand
}
request.LifecycleCommand = &lifecycleCommand
}

response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().UpgradeLifecycleHook(request)
Expand Down
14 changes: 8 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,14 @@ 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
lifecycle_transition_type = "NORMAL"
# lifecycle_transition_type = "EXTENSION"
notification_metadata = "tf test"
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Example Usage

```hcl
resource "tencentcloud_as_start_instance_refresh" "example" {
auto_scaling_group_id = "asg-9dn1a5y6"
auto_scaling_group_id = "asg-8n7fdm28"
refresh_mode = "ROLLING_UPDATE_RESET"
refresh_settings {
check_instance_target_health = false
rolling_update_settings {
batch_number = 1
batch_pause = "AUTOMATIC"
max_surge = 1
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions website/docs/r/as_lifecycle_hook.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ 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
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
lifecycle_transition_type = "NORMAL"
# lifecycle_transition_type = "EXTENSION"
notification_metadata = "tf test"
}
```
Expand Down Expand Up @@ -121,6 +123,7 @@ The following arguments are supported:
* `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.
* `lifecycle_transition_type` - (Optional, String) The scenario where the lifecycle hook is applied. `EXTENSION`: the lifecycle hook will be triggered when AttachInstances, DetachInstances or RemoveInstaces is called. `NORMAL`: the lifecycle hook is not triggered by the above APIs.
* `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`, `TDMQ_CMQ_QUEUE`, `TDMQ_CMQ_TOPIC`.
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/as_start_instance_refresh.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ Provides a resource to create as instance refresh

```hcl
resource "tencentcloud_as_start_instance_refresh" "example" {
auto_scaling_group_id = "asg-9dn1a5y6"
auto_scaling_group_id = "asg-8n7fdm28"
refresh_mode = "ROLLING_UPDATE_RESET"
refresh_settings {
check_instance_target_health = false
rolling_update_settings {
batch_number = 1
batch_pause = "AUTOMATIC"
max_surge = 1
}
}
}
Expand Down
Loading