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

Fix: Setting default values for scale_in_protected_instances and standby_instances as per documentation #33382

Merged
merged 7 commits into from
Sep 11, 2023
7 changes: 7 additions & 0 deletions .changelog/33382.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_autoscaling_group: Fix `ValidationError` errors when starting Auto Scaling group instance refresh
```

```release-note:enhancement
resource/aws_autoscaling_group: Change the default values of `instance_refresh.preferences.scale_in_protected_instances` and `instance_refresh.preferences.standby_instances` from `Wait` to the [Amazon EC2 Auto Scaling console recommended value](https://docs.aws.amazon.com/autoscaling/ec2/userguide/understand-instance-refresh-default-values.html) of `Ignore`
```
2 changes: 2 additions & 0 deletions internal/service/autoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func ResourceGroup() *schema.Resource {
"scale_in_protected_instances": {
Type: schema.TypeString,
Optional: true,
Default: autoscaling.ScaleInProtectedInstancesIgnore,
ValidateFunc: validation.StringInSlice(autoscaling.ScaleInProtectedInstances_Values(), false),
},
"skip_matching": {
Expand All @@ -221,6 +222,7 @@ func ResourceGroup() *schema.Resource {
"standby_instances": {
Type: schema.TypeString,
Optional: true,
Default: autoscaling.StandbyInstancesIgnore,
ValidateFunc: validation.StringInSlice(autoscaling.StandbyInstances_Values(), false),
},
},
Expand Down
35 changes: 19 additions & 16 deletions internal/service/autoscaling/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1222,9 +1222,9 @@ func TestAccAutoScalingGroup_InstanceRefresh_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.checkpoint_percentages.#", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.instance_warmup", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.min_healthy_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.skip_matching", "false"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.strategy", "Rolling"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.triggers.#", "0"),
),
Expand All @@ -1240,9 +1240,9 @@ func TestAccAutoScalingGroup_InstanceRefresh_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.checkpoint_percentages.#", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.instance_warmup", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.min_healthy_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.skip_matching", "true"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.strategy", "Rolling"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.triggers.#", "0"),
),
Expand All @@ -1258,9 +1258,9 @@ func TestAccAutoScalingGroup_InstanceRefresh_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.checkpoint_percentages.#", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.instance_warmup", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.min_healthy_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", "Wait"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.skip_matching", "false"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.strategy", "Rolling"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.triggers.#", "0"),
),
Expand All @@ -1276,9 +1276,9 @@ func TestAccAutoScalingGroup_InstanceRefresh_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.checkpoint_percentages.#", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.instance_warmup", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.min_healthy_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.skip_matching", "false"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", "Wait"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.strategy", "Rolling"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.triggers.#", "0"),
),
Expand All @@ -1299,9 +1299,9 @@ func TestAccAutoScalingGroup_InstanceRefresh_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.checkpoint_percentages.4", "100"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.instance_warmup", "10"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.min_healthy_percentage", "50"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", "Refresh"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.skip_matching", "false"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", "Terminate"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.strategy", "Rolling"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.triggers.#", "0"),
),
Expand Down Expand Up @@ -1424,9 +1424,9 @@ func TestAccAutoScalingGroup_InstanceRefresh_autoRollback(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.checkpoint_percentages.#", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.instance_warmup", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.min_healthy_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.skip_matching", "false"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.strategy", "Rolling"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.triggers.#", "0"),
),
Expand All @@ -1442,9 +1442,9 @@ func TestAccAutoScalingGroup_InstanceRefresh_autoRollback(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.checkpoint_percentages.#", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.instance_warmup", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.min_healthy_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.scale_in_protected_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.skip_matching", "false"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", ""),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.preferences.0.standby_instances", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.strategy", "Rolling"),
resource.TestCheckResourceAttr(resourceName, "instance_refresh.0.triggers.#", "0"),
),
Expand Down Expand Up @@ -4944,7 +4944,7 @@ resource "aws_autoscaling_group" "test" {

preferences {
min_healthy_percentage = 0
scale_in_protected_instances = "Ignore"
scale_in_protected_instances = "Wait"
}
}

Expand Down Expand Up @@ -4972,7 +4972,7 @@ resource "aws_autoscaling_group" "test" {

preferences {
min_healthy_percentage = 0
standby_instances = "Ignore"
standby_instances = "Wait"
}
}

Expand Down Expand Up @@ -5035,6 +5035,9 @@ resource "aws_autoscaling_group" "test" {
min_healthy_percentage = 50
checkpoint_delay = 25
checkpoint_percentages = [1, 20, 25, 50, 100]

scale_in_protected_instances = "Refresh"
standby_instances = "Terminate"
}
}

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/autoscaling_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ This configuration block supports the following:
- `min_healthy_percentage` - (Optional) Amount of capacity in the Auto Scaling group that must remain healthy during an instance refresh to allow the operation to continue, as a percentage of the desired capacity of the Auto Scaling group. Defaults to `90`.
- `skip_matching` - (Optional) Replace instances that already have your desired configuration. Defaults to `false`.
- `auto_rollback` - (Optional) Automatically rollback if instance refresh fails. Defaults to `false`. This option may only be set to `true` when specifying a `launch_template` or `mixed_instances_policy`.
- `scale_in_protected_instances` - (Optional) Behavior when encountering instances protected from scale in are found. Available behaviors are `Refresh`, `Ignore`, and `Wait`. Default is `Wait`.
- `standby_instances` - (Optional) Behavior when encountering instances in the `Standby` state in are found. Available behaviors are `Terminate`, `Ignore`, and `Wait`. Default is `Wait`.
- `scale_in_protected_instances` - (Optional) Behavior when encountering instances protected from scale in are found. Available behaviors are `Refresh`, `Ignore`, and `Wait`. Default is `Ignore`.
- `standby_instances` - (Optional) Behavior when encountering instances in the `Standby` state in are found. Available behaviors are `Terminate`, `Ignore`, and `Wait`. Default is `Ignore`.
- `triggers` - (Optional) Set of additional property names that will trigger an Instance Refresh. A refresh will always be triggered by a change in any of `launch_configuration`, `launch_template`, or `mixed_instances_policy`.

~> **NOTE:** A refresh is started when any of the following Auto Scaling Group properties change: `launch_configuration`, `launch_template`, `mixed_instances_policy`. Additional properties can be specified in the `triggers` property of `instance_refresh`.
Expand Down