Skip to content

Commit

Permalink
fix(as): [121458126] tencentcloud_as_scaling_group support new para…
Browse files Browse the repository at this point in the history
…ms (#3048)

* add

* add
  • Loading branch information
SevenEarth authored Dec 31, 2024
1 parent 711335d commit 3d8c5c5
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .changelog/3048.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_as_scaling_group: support `replace_mode`, `desired_capacity_sync_with_max_min_size` params
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.763
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.825
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1052
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1071
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.1071
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat v1.0.825
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.825 h1:yiC2lsZ
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.825/go.mod h1:6qtSa8OZKwJOWoOCYWVZd6+T62O96AxbPll0I43d4yw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1052 h1:d7eK/iFBAL1P75UWcc+wupp2/W1KQHdTxB/YpJTaoUA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1052/go.mod h1:o/8YQckpRRJ12COW2g9J9Fx+v5noOAsHkKVQpTctM+g=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1071 h1:XtAPtAaj4rxUnxhLHhwk104R7ThGQI1E7Hnub4YXCB8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1071/go.mod h1:KiAIwNj6ovl/d1WOM7WFNdW6s9TsbYCq9xksjOQsQ7k=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824 h1:DVKvZ6h+qd7tadUrCjVAkCCmE3TsbK2ZmwGd3AJcpWc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824/go.mod h1:DvBpDX/qdJG4KKLeULmRvhAjPYiw8za0HeTSu2y/lFw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.1051 h1:ZwWmhAxXd88JDPs/8s2qW9SJblXNhIXWKWfeW7jtjlc=
Expand Down
5 changes: 5 additions & 0 deletions tencentcloud/services/as/extension_as.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ const (
SCALING_MODE_WAKE_UP_STOPPED = "WAKE_UP_STOPPED_SCALING"
)

const (
REPLACE_MODE_RECREATE = "RECREATE"
REPLACE_MODE_RESET = "RESET"
)

const (
REFRESH_ACTIVITIES_SUCCESSFUL = "SUCCESSFUL"
)
87 changes: 61 additions & 26 deletions tencentcloud/services/as/resource_tc_as_scaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,32 @@ func ResourceTencentCloudAsScalingGroup() *schema.Resource {
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{SCALING_GROUP_RETRY_POLICY_IMMEDIATE_RETRY,
SCALING_GROUP_RETRY_POLICY_INCREMENTAL_INTERVALS}),
},
"scaling_mode": {
Type: schema.TypeString,
Optional: true,
Description: "Indicates scaling mode which creates and terminates instances (classic method), or method first tries to start stopped instances (wake up stopped) to perform scaling operations. Available values: `CLASSIC_SCALING`, `WAKE_UP_STOPPED_SCALING`. Default: `CLASSIC_SCALING`.",
},
// Service Settings
"replace_monitor_unhealthy": {
Type: schema.TypeBool,
Optional: true,
Description: "Enables unhealthy instance replacement. If set to `true`, AS will replace instances that are flagged as unhealthy by Cloud Monitor.",
},
"scaling_mode": {
Type: schema.TypeString,
Optional: true,
Description: "Indicates scaling mode which creates and terminates instances (classic method), or method first tries to start stopped instances (wake up stopped) to perform scaling operations. Available values: `CLASSIC_SCALING`, `WAKE_UP_STOPPED_SCALING`. Default: `CLASSIC_SCALING`.",
},
"replace_load_balancer_unhealthy": {
Type: schema.TypeBool,
Optional: true,
Description: "Enable unhealthy instance replacement. If set to `true`, AS will replace instances that are found unhealthy in the CLB health check.",
},
"replace_mode": {
Type: schema.TypeString,
Optional: true,
Description: "Replace mode of unhealthy replacement service. Valid values: RECREATE: Rebuild an instance to replace the original unhealthy instance. RESET: Performing a system reinstallation on unhealthy instances to keep information such as data disks, private IP addresses, and instance IDs unchanged. The instance login settings, HostName, enhanced services, and UserData will remain consistent with the current launch configuration. Default value: RECREATE. Note: This field may return null, indicating that no valid values can be obtained.",
},
"desired_capacity_sync_with_max_min_size": {
Type: schema.TypeBool,
Optional: true,
Description: "The expected number of instances is synchronized with the maximum and minimum values. The default value is `False`. This parameter is effective only in the scenario where the expected number is not passed in when modifying the scaling group interface. True: When modifying the maximum or minimum value, if there is a conflict with the current expected number, the expected number is adjusted synchronously. For example, when modifying, if the minimum value 2 is passed in and the current expected number is 1, the expected number is adjusted synchronously to 2; False: When modifying the maximum or minimum value, if there is a conflict with the current expected number, an error message is displayed indicating that the modification is not allowed.",
},
"health_check_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -315,20 +325,28 @@ func resourceTencentCloudAsScalingGroupCreate(d *schema.ResourceData, meta inter
}

var (
scalingMode = d.Get("scaling_mode").(string)
replaceMonitorUnhealthy = d.Get("replace_monitor_unhealthy").(bool)
replaceLBUnhealthy = d.Get("replace_load_balancer_unhealthy").(bool)
replaceMonitorUnhealthy = d.Get("replace_monitor_unhealthy").(bool)
scalingMode = d.Get("scaling_mode").(string)
replaceLBUnhealthy = d.Get("replace_load_balancer_unhealthy").(bool)
replaceMode = d.Get("replace_mode").(string)
desiredCapacitySyncWithMaxMinSize = d.Get("desired_capacity_sync_with_max_min_size").(bool)
)

if scalingMode != "" || replaceMonitorUnhealthy || replaceLBUnhealthy {
if replaceMonitorUnhealthy || scalingMode != "" || replaceLBUnhealthy || replaceMode != "" || desiredCapacitySyncWithMaxMinSize {
if scalingMode == "" {
scalingMode = SCALING_MODE_CLASSIC
}

if replaceMode == "" {
replaceMode = REPLACE_MODE_RECREATE
}

request.ServiceSettings = &as.ServiceSettings{
ScalingMode: &scalingMode,
ReplaceMonitorUnhealthy: &replaceMonitorUnhealthy,
ReplaceLoadBalancerUnhealthy: &replaceLBUnhealthy,
ReplaceMonitorUnhealthy: &replaceMonitorUnhealthy,
ScalingMode: &scalingMode,
ReplaceLoadBalancerUnhealthy: &replaceLBUnhealthy,
ReplaceMode: &replaceMode,
DesiredCapacitySyncWithMaxMinSize: &desiredCapacitySyncWithMaxMinSize,
}
}

Expand Down Expand Up @@ -356,8 +374,8 @@ func resourceTencentCloudAsScalingGroupCreate(d *schema.ResourceData, meta inter
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if response.Response.AutoScalingGroupId == nil {
err = fmt.Errorf("Auto scaling group id is nil")
if response == nil || response.Response == nil || response.Response.AutoScalingGroupId == nil {
err = fmt.Errorf("Create auto scaling group failed, Auto scaling group id is nil.")
return resource.NonRetryableError(err)
}

Expand All @@ -378,7 +396,7 @@ func resourceTencentCloudAsScalingGroupCreate(d *schema.ResourceData, meta inter
if errRet != nil {
return tccommon.RetryError(errRet, tccommon.InternalError)
}
if scalingGroup != nil && *scalingGroup.InActivityStatus == SCALING_GROUP_NOT_IN_ACTIVITY_STATUS {
if scalingGroup != nil && scalingGroup.InActivityStatus != nil && *scalingGroup.InActivityStatus == SCALING_GROUP_NOT_IN_ACTIVITY_STATUS {
return nil
}
return resource.RetryableError(fmt.Errorf("scaling group status is %s, retry...", *scalingGroup.InActivityStatus))
Expand Down Expand Up @@ -445,18 +463,26 @@ func resourceTencentCloudAsScalingGroupRead(d *schema.ResourceData, meta interfa
_ = d.Set("multi_zone_subnet_policy", scalingGroup.MultiZoneSubnetPolicy)
}

if v := d.Get("scaling_mode"); v != "" {
_ = d.Set("scaling_mode", v.(string))
}

if v, ok := d.GetOk("replace_monitor_unhealthy"); ok {
_ = d.Set("replace_monitor_unhealthy", v.(bool))
}

if v := d.Get("scaling_mode"); v != "" {
_ = d.Set("scaling_mode", v.(string))
}

if v, ok := d.GetOk("replace_load_balancer_unhealthy"); ok {
_ = d.Set("replace_load_balancer_unhealthy", v.(bool))
}

if v := d.Get("replace_mode"); v != "" {
_ = d.Set("replace_mode", v.(string))
}

if v, ok := d.GetOk("desired_capacity_sync_with_max_min_size"); ok {
_ = d.Set("desired_capacity_sync_with_max_min_size", v.(bool))
}

if scalingGroup.ForwardLoadBalancerSet != nil && len(scalingGroup.ForwardLoadBalancerSet) > 0 {
forwardLoadBalancers := make([]map[string]interface{}, 0, len(scalingGroup.ForwardLoadBalancerSet))
for _, v := range scalingGroup.ForwardLoadBalancerSet {
Expand Down Expand Up @@ -578,20 +604,29 @@ func resourceTencentCloudAsScalingGroupUpdate(d *schema.ResourceData, meta inter
request.MultiZoneSubnetPolicy = helper.String(d.Get("multi_zone_subnet_policy").(string))
}

if d.HasChange("scaling_mode") ||
d.HasChange("replace_monitor_unhealthy") ||
d.HasChange("replace_load_balancer_unhealthy") {
updateAttrs = append(updateAttrs, "scaling_mode", "replace_monitor_unhealthy", "replace_load_balancer_unhealthy")
if d.HasChange("replace_monitor_unhealthy") ||
d.HasChange("scaling_mode") ||
d.HasChange("replace_load_balancer_unhealthy") ||
d.HasChange("replace_mode") ||
d.HasChange("desired_capacity_sync_with_max_min_size") {
updateAttrs = append(updateAttrs, "replace_monitor_unhealthy", "scaling_mode", "replace_load_balancer_unhealthy", "replace_mode", "desired_capacity_sync_with_max_min_size")
scalingMode := d.Get("scaling_mode").(string)
replaceMode := d.Get("replace_mode").(string)
if scalingMode == "" {
scalingMode = SCALING_MODE_CLASSIC
}
if replaceMode == "" {
replaceMode = REPLACE_MODE_RECREATE
}
replaceMonitor := d.Get("replace_monitor_unhealthy").(bool)
replaceLB := d.Get("replace_load_balancer_unhealthy").(bool)
desiredCapacitySyncWithMaxMinSize := d.Get("desired_capacity_sync_with_max_min_size").(bool)
request.ServiceSettings = &as.ServiceSettings{
ScalingMode: &scalingMode,
ReplaceMonitorUnhealthy: &replaceMonitor,
ReplaceLoadBalancerUnhealthy: &replaceLB,
ReplaceMonitorUnhealthy: &replaceMonitor,
ScalingMode: &scalingMode,
ReplaceLoadBalancerUnhealthy: &replaceLB,
ReplaceMode: &replaceMode,
DesiredCapacitySyncWithMaxMinSize: &desiredCapacitySyncWithMaxMinSize,
}
}

Expand Down
31 changes: 18 additions & 13 deletions tencentcloud/services/as/resource_tc_as_scaling_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,22 @@ resource "tencentcloud_clb_listener_rule" "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]
project_id = 0
default_cooldown = 400
desired_capacity = 1
termination_policies = ["NEWEST_INSTANCE"]
retry_policy = "INCREMENTAL_INTERVALS"
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]
project_id = 0
default_cooldown = 400
desired_capacity = 1
replace_monitor_unhealthy = false
scaling_mode = "CLASSIC_SCALING"
replace_load_balancer_unhealthy = false
replace_mode = "RECREATE"
desired_capacity_sync_with_max_min_size = false
termination_policies = ["NEWEST_INSTANCE"]
retry_policy = "INCREMENTAL_INTERVALS"
forward_balancer_ids {
load_balancer_id = tencentcloud_clb_instance.example.id
Expand All @@ -102,7 +107,7 @@ resource "tencentcloud_as_scaling_group" "example" {
}
tags = {
"createBy" = "tfExample"
createBy = "tfExample"
}
}
```
Expand All @@ -112,5 +117,5 @@ Import
AutoScaling Groups can be imported using the id, e.g.

```
$ terraform import tencentcloud_as_scaling_group.scaling_group asg-n32ymck2
$ terraform import tencentcloud_as_scaling_group.example asg-n32ymck2
```
3 changes: 3 additions & 0 deletions tencentcloud/services/as/service_tencentcloud_as.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func (me *AsService) DescribeAutoScalingGroupById(ctx context.Context, scalingGr
errRet = err
return
}
if response == nil || response.Response == nil || response.Response.AutoScalingGroupSet == nil {
return
}
has = len(response.Response.AutoScalingGroupSet)
if has < 1 {
return
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.825
## explicit; go 1.14
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm/v20210622
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1052
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1071
## explicit; go 1.14
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824
Expand Down
Loading

0 comments on commit 3d8c5c5

Please sign in to comment.