From b8ed842b595daf062e4875abd5c49c8790fb6ecd Mon Sep 17 00:00:00 2001 From: hellertang Date: Wed, 6 Nov 2024 20:21:21 +0800 Subject: [PATCH 1/3] add lifecycle_transition_type --- .../as/resource_tc_as_lifecycle_hook.go | 32 ++++++++++++++----- .../as/resource_tc_as_lifecycle_hook.md | 14 ++++---- .../resource_tc_as_start_instance_refresh.md | 3 +- .../docs/r/as_lifecycle_hook.html.markdown | 13 +++++--- .../r/as_start_instance_refresh.html.markdown | 3 +- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/tencentcloud/services/as/resource_tc_as_lifecycle_hook.go b/tencentcloud/services/as/resource_tc_as_lifecycle_hook.go index 024c20fba0..6a6ca51e7b 100644 --- a/tencentcloud/services/as/resource_tc_as_lifecycle_hook.go +++ b/tencentcloud/services/as/resource_tc_as_lifecycle_hook.go @@ -77,6 +77,11 @@ 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, + 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, @@ -122,6 +127,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)) @@ -200,6 +208,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 { @@ -247,6 +258,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)) @@ -265,15 +279,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) diff --git a/tencentcloud/services/as/resource_tc_as_lifecycle_hook.md b/tencentcloud/services/as/resource_tc_as_lifecycle_hook.md index daa66f13b7..3b7c7ccf57 100644 --- a/tencentcloud/services/as/resource_tc_as_lifecycle_hook.md +++ b/tencentcloud/services/as/resource_tc_as_lifecycle_hook.md @@ -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" } ``` diff --git a/tencentcloud/services/as/resource_tc_as_start_instance_refresh.md b/tencentcloud/services/as/resource_tc_as_start_instance_refresh.md index 2b0e211fc6..2924c3a2d2 100644 --- a/tencentcloud/services/as/resource_tc_as_start_instance_refresh.md +++ b/tencentcloud/services/as/resource_tc_as_start_instance_refresh.md @@ -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 } } } diff --git a/website/docs/r/as_lifecycle_hook.html.markdown b/website/docs/r/as_lifecycle_hook.html.markdown index 0f9c8097e5..880cc67d55 100644 --- a/website/docs/r/as_lifecycle_hook.html.markdown +++ b/website/docs/r/as_lifecycle_hook.html.markdown @@ -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" } ``` @@ -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`. diff --git a/website/docs/r/as_start_instance_refresh.html.markdown b/website/docs/r/as_start_instance_refresh.html.markdown index 7553acb82f..00a87cfaf2 100644 --- a/website/docs/r/as_start_instance_refresh.html.markdown +++ b/website/docs/r/as_start_instance_refresh.html.markdown @@ -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 } } } From 6cef7eed99be0a484c7265268e2297609f149c6f Mon Sep 17 00:00:00 2001 From: hellertang Date: Wed, 6 Nov 2024 20:22:26 +0800 Subject: [PATCH 2/3] add lifecycle_transition_type --- .changelog/2943.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2943.txt diff --git a/.changelog/2943.txt b/.changelog/2943.txt new file mode 100644 index 0000000000..64d6e70436 --- /dev/null +++ b/.changelog/2943.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_as_lifecycle_hook: add `lifecycle_transition_type` +``` \ No newline at end of file From 49967b0d251d7684bb65231f352b4208a11c1811 Mon Sep 17 00:00:00 2001 From: hellertang Date: Wed, 6 Nov 2024 20:32:26 +0800 Subject: [PATCH 3/3] add lifecycle_transition_type --- tencentcloud/services/as/resource_tc_as_lifecycle_hook.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tencentcloud/services/as/resource_tc_as_lifecycle_hook.go b/tencentcloud/services/as/resource_tc_as_lifecycle_hook.go index 6a6ca51e7b..3055980f53 100644 --- a/tencentcloud/services/as/resource_tc_as_lifecycle_hook.go +++ b/tencentcloud/services/as/resource_tc_as_lifecycle_hook.go @@ -80,6 +80,7 @@ func ResourceTencentCloudAsLifecycleHook() *schema.Resource { "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": {