Skip to content

fix(as): [121458126] tencentcloud_as_scaling_group support new params #3048

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 2 commits into from
Dec 31, 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/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
```
4 changes: 2 additions & 2 deletions 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.1051
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat v1.0.825
Expand All @@ -46,7 +46,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1034
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1046
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1068
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1071
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1053
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1058
Expand Down
4 changes: 4 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 Expand Up @@ -943,6 +945,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1066 h1:D55
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1066/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1068 h1:mI0xoreGp9GkDJWkdzqgZcPsfoWXciahPAvEcaGSA6g=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1068/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1071 h1:Q/Ue/yRv4HSpaiFAnXIshoDjxzwyhwezEidXU49Boa4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1071/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
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.

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

4 changes: 2 additions & 2 deletions 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 Expand Up @@ -1163,7 +1163,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit/v20190319
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1046
## explicit; go 1.14
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1068
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1071
## explicit; go 1.11
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors
Expand Down
Loading
Loading