Skip to content
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

Add default_instance_warmup attribute to aws_autoscaling_group #25722

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/25722.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_autoscaling_group: Add `default_instance_warmup` attribute
```
13 changes: 13 additions & 0 deletions internal/service/autoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func ResourceGroup() *schema.Resource {
Optional: true,
Computed: true,
},
"default_instance_warmup": {
Type: schema.TypeInt,
Optional: true,
},
"desired_capacity": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -878,6 +882,10 @@ func resourceGroupCreate(d *schema.ResourceData, meta interface{}) error {
createInput.DefaultCooldown = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("default_instance_warmup"); ok {
createInput.DefaultInstanceWarmup = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("health_check_type"); ok {
createInput.HealthCheckType = aws.String(v.(string))
}
Expand Down Expand Up @@ -1031,6 +1039,7 @@ func resourceGroupRead(d *schema.ResourceData, meta interface{}) error {
d.Set("capacity_rebalance", g.CapacityRebalance)
d.Set("context", g.Context)
d.Set("default_cooldown", g.DefaultCooldown)
d.Set("default_instance_warmup", g.DefaultInstanceWarmup)
d.Set("desired_capacity", g.DesiredCapacity)
if len(g.EnabledMetrics) > 0 {
d.Set("enabled_metrics", flattenEnabledMetrics(g.EnabledMetrics))
Expand Down Expand Up @@ -1162,6 +1171,10 @@ func resourceGroupUpdate(d *schema.ResourceData, meta interface{}) error {
input.DefaultCooldown = aws.Int64(int64(d.Get("default_cooldown").(int)))
}

if d.HasChange("default_instance_warmup") {
input.DefaultInstanceWarmup = aws.Int64(int64(d.Get("default_instance_warmup").(int)))
}

if d.HasChange("desired_capacity") {
input.DesiredCapacity = aws.Int64(int64(d.Get("desired_capacity").(int)))
shouldWaitForCapacity = true
Expand Down
44 changes: 44 additions & 0 deletions internal/service/autoscaling/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestAccAutoScalingGroup_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "capacity_rebalance", "false"),
resource.TestCheckResourceAttr(resourceName, "context", ""),
resource.TestCheckResourceAttr(resourceName, "default_cooldown", "300"),
resource.TestCheckResourceAttr(resourceName, "default_instance_warmup", "0"),
resource.TestCheckResourceAttr(resourceName, "desired_capacity", "0"),
resource.TestCheckResourceAttr(resourceName, "enabled_metrics.#", "0"),
resource.TestCheckResourceAttr(resourceName, "force_delete", "false"),
Expand Down Expand Up @@ -128,6 +129,36 @@ func TestAccAutoScalingGroup_disappears(t *testing.T) {
})
}

func TestAccAutoScalingGroup_defaultInstanceWarmup(t *testing.T) {
var group autoscaling.Group
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_autoscaling_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, autoscaling.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccGroupConfig_defaultInstanceWarmup(rName, 30),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupExists(resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "default_instance_warmup", "30"),
),
},
testAccGroupImportStep(resourceName),
{
Config: testAccGroupConfig_defaultInstanceWarmup(rName, 15),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupExists(resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "default_instance_warmup", "15"),
),
},
},
})
}

func TestAccAutoScalingGroup_nameGenerated(t *testing.T) {
var group autoscaling.Group
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -3278,6 +3309,19 @@ resource "aws_autoscaling_group" "test" {
`, rName))
}

func testAccGroupConfig_defaultInstanceWarmup(rName string, defaultInstanceWarmup int) string {
return acctest.ConfigCompose(testAccGroupLaunchConfigurationBaseConfig(rName, "t2.micro"), fmt.Sprintf(`
resource "aws_autoscaling_group" "test" {
availability_zones = [data.aws_availability_zones.available.names[0]]
max_size = 0
min_size = 0
name = %[1]q
default_instance_warmup = %[2]d
launch_configuration = aws_launch_configuration.test.name
}
`, rName, defaultInstanceWarmup))
}

func testAccGroupConfig_nameGenerated(rName string) string {
return acctest.ConfigCompose(testAccGroupLaunchConfigurationBaseConfig(rName, "t2.micro"), `
resource "aws_autoscaling_group" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/autoscaling_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ The following arguments are supported:
* `capacity_rebalance` - (Optional) Indicates whether capacity rebalance is enabled. Otherwise, capacity rebalance is disabled.
* `context` - (Optional) Reserved.
* `default_cooldown` - (Optional) The amount of time, in seconds, after a scaling activity completes before another scaling activity can start.
* `default_instance_warmup` - (Optional) The amount of time, in seconds, until a newly launched instance can contribute to the Amazon CloudWatch metrics. This delay lets an instance finish initializing before Amazon EC2 Auto Scaling aggregates instance metrics, resulting in more reliable usage data. Set this value equal to the amount of time that it takes for resource consumption to become stable after an instance reaches the InService state. (See [Set the default instance warmup for an Auto Scaling group](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-default-instance-warmup.html))
* `launch_configuration` - (Optional) The name of the launch configuration to use.
* `launch_template` - (Optional) Nested argument with Launch template specification to use to launch instances. See [Launch Template](#launch_template) below for more details.
* `mixed_instances_policy` (Optional) Configuration block containing settings to define launch targets for Auto Scaling groups. See [Mixed Instances Policy](#mixed_instances_policy) below for more details.
Expand Down Expand Up @@ -662,6 +663,7 @@ In addition to all arguments above, the following attributes are exported:
* `min_size` - The minimum size of the Auto Scaling Group
* `max_size` - The maximum size of the Auto Scaling Group
* `default_cooldown` - Time between a scaling activity and the succeeding scaling activity.
* `default_instance_warmup` - The duration of the default instance warmup, in seconds.
* `name` - The name of the Auto Scaling Group
* `health_check_grace_period` - Time after instance comes into service before checking health.
* `health_check_type` - "EC2" or "ELB". Controls how health checking is done.
Expand Down