Skip to content

Commit

Permalink
resource/alicloud_ess_scaling_group: add attribute of stop_instance_t…
Browse files Browse the repository at this point in the history
…imeout.
  • Loading branch information
fuliu-zln authored and ChenHanZhang committed Dec 9, 2024
1 parent aea6aec commit fe93ca4
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 5 deletions.
19 changes: 19 additions & 0 deletions alicloud/resource_alicloud_ess_scaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func resourceAlicloudEssScalingGroup() *schema.Resource {
Required: true,
ValidateFunc: IntBetween(0, 2000),
},
"stop_instance_timeout": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: IntBetween(30, 240),
},
"desired_capacity": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -319,6 +324,9 @@ func resourceAliyunEssScalingGroupRead(d *schema.ResourceData, meta interface{})

d.Set("min_size", object["MinSize"])
d.Set("max_size", object["MaxSize"])
if object["StopInstanceTimeout"] != nil {
d.Set("stop_instance_timeout", object["StopInstanceTimeout"])
}
d.Set("resource_group_id", object["ResourceGroupId"])
d.Set("desired_capacity", object["DesiredCapacity"])
d.Set("scaling_group_name", object["ScalingGroupName"])
Expand Down Expand Up @@ -494,6 +502,13 @@ func resourceAliyunEssScalingGroupUpdate(d *schema.ResourceData, meta interface{
if d.HasChange("max_size") {
request["MaxSize"] = requests.NewInteger(d.Get("max_size").(int))
}

if d.HasChange("stop_instance_timeout") {
if v, ok := d.GetOkExists("stop_instance_timeout"); ok {
request["StopInstanceTimeout"] = requests.NewInteger(v.(int))
}
}

if d.HasChange("desired_capacity") {
if v, ok := d.GetOkExists("desired_capacity"); ok {
request["DesiredCapacity"] = requests.NewInteger(v.(int))
Expand Down Expand Up @@ -746,6 +761,10 @@ func buildAlicloudEssScalingGroupArgs(d *schema.ResourceData, meta interface{})
request["DesiredCapacity"] = v
}

if v, ok := d.GetOk("stop_instance_timeout"); ok {
request["StopInstanceTimeout"] = v
}

if v, ok := d.GetOk("max_instance_lifetime"); ok {
request["MaxInstanceLifetime"] = v
}
Expand Down
107 changes: 102 additions & 5 deletions alicloud/resource_alicloud_ess_scaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,106 @@ func TestAccAliCloudEssScalingGroup_scalingPolicy_maxInstanceLifetime(t *testing

}

func TestAccAliCloudEssScalingGroup_scalingPolicy_stopInstanceTimeout(t *testing.T) {
rand := acctest.RandIntRange(10000, 999999)
var v ess.ScalingGroup
resourceId := "alicloud_ess_scaling_group.default"

basicMap := map[string]string{
"min_size": "1",
"max_size": "1",
"default_cooldown": "20",
"scaling_group_name": fmt.Sprintf("tf-testAccEssScalingGroup-%d", rand),
"vswitch_ids.#": "2",
"removal_policies.#": "2",
"on_demand_base_capacity": "10",
"spot_instance_pools": "10",
"spot_instance_remedy": "false",
"group_deletion_protection": "false",
"on_demand_percentage_above_base_capacity": "10",
"az_balance": "false",
"allocation_strategy": "priority",
"spot_allocation_strategy": "priority",
}

ra := resourceAttrInit(resourceId, basicMap)
rc := resourceCheckInit(resourceId, &v, func() interface{} {
return &EssService{testAccProvider.Meta().(*connectivity.AliyunClient)}
})
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
name := fmt.Sprintf("tf-testAccEssScalingGroup-%d", rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceEssScalingGroupDependence)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},

// module name
IDRefreshName: resourceId,

Providers: testAccProviders,
CheckDestroy: testAccCheckEssScalingGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"min_size": "1",
"max_size": "1",
"scaling_group_name": "${var.name}",
"default_cooldown": "20",
"vswitch_ids": []string{"${alicloud_vswitch.default.id}", "${alicloud_vswitch.default2.id}"},
"removal_policies": []string{"OldestInstance", "NewestInstance"},
"multi_az_policy": "COMPOSABLE",
"on_demand_base_capacity": "10",
"on_demand_percentage_above_base_capacity": "10",
"spot_instance_pools": "10",
"az_balance": "false",
"allocation_strategy": "priority",
"scaling_policy": "release",
"spot_allocation_strategy": "priority",
"stop_instance_timeout": "30",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(nil),
),
},
{
Config: testAccConfig(map[string]interface{}{
"min_size": "1",
"max_size": "1",
"scaling_policy": "forceRelease",
"max_instance_lifetime": "86400",
"scaling_group_name": "${var.name}",
"default_cooldown": "20",
"vswitch_ids": []string{"${alicloud_vswitch.default.id}", "${alicloud_vswitch.default2.id}"},
"removal_policies": []string{"OldestInstance", "NewestInstance"},
"multi_az_policy": "COMPOSABLE",
"on_demand_base_capacity": "10",
"on_demand_percentage_above_base_capacity": "10",
"spot_instance_pools": "10",
"spot_instance_remedy": "true",
"az_balance": "false",
"allocation_strategy": "priority",
"spot_allocation_strategy": "priority",
"stop_instance_timeout": "240",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"spot_instance_remedy": "true",
"az_balance": "false",
"scaling_policy": "forceRelease",
"max_instance_lifetime": "86400",
"allocation_strategy": "priority",
"spot_allocation_strategy": "priority",
"stop_instance_timeout": "240",
}),
),
},
},
})

}

func TestAccAliCloudEssScalingGroup_vpc(t *testing.T) {
rand := acctest.RandIntRange(10000, 999999)
var v ess.ScalingGroup
Expand Down Expand Up @@ -2368,7 +2468,6 @@ func resourceEssScalingAttachmentConfigDependence(name string) string {
owners = "system"
}
data "alicloud_instance_types" "c6" {
instance_type_family = "ecs.c6"
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
}
Expand Down Expand Up @@ -2591,8 +2690,7 @@ func resourceEssScalingGroupTemplate(name string) string {
owners = "system"
}
data "alicloud_instance_types" "c6" {
instance_type_family = "ecs.c6"
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
}
resource "alicloud_ecs_launch_template" "default3" {
Expand Down Expand Up @@ -2740,8 +2838,7 @@ func resourceEssScalingGroupAlbServerGroup(name string) string {
owners = "system"
}
data "alicloud_instance_types" "c6" {
instance_type_family = "ecs.c6"
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
}
resource "alicloud_ecs_launch_template" "default3" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ess_scaling_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ The following arguments are supported:
* `container_group_id` - (Optional, ForceNew, Available since v1.233.0) The ID of the elastic container instance.
* `scaling_policy` - (Optional, Available since v1.227.0) The reclaim mode of the scaling group. Optional values: recycle, release, forceRecycle, forceRelease.
* `max_instance_lifetime` - (Optional, Available since v1.227.0) The maximum life span of an instance in the scaling group. Unit: seconds.
* `stop_instance_timeout` - (Optional, Available since v1.238.0) The period of time required by the ECS instance to enter the Stopped state. Unit: seconds. Valid values: 30 to 240.
* `tags` - (Optional, Available since v1.160.0) A mapping of tags to assign to the resource.
- Key: It can be up to 64 characters in length. It cannot begin with "aliyun", "acs:", "http://", or "https://". It cannot be a null string.
- Value: It can be up to 128 characters in length. It cannot begin with "aliyun", "acs:", "http://", or "https://". It can be a null string.
Expand Down

0 comments on commit fe93ca4

Please sign in to comment.