hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.83k stars 9.17k forks source link

Updating capacity of autoscaling group fails if desired_capacity in state is outside range of min_size and max_size, and isn't in config #26230

Open tmccombs opened 2 years ago

tmccombs commented 2 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

resource "aws_autoscaling_group" "example" {

  name                      = "example"
  max_size                  = 3 
  min_size                  = 6
  vpc_zone_identifier       = var.vpc_id
  health_check_grace_period = var.health_check_grace_period
  target_group_arns         = var.target_group_arns
  default_cooldown          = 300
  termination_policies      = ["OldestInstance"]

  launch_template {
    id      = var.launch_template_id
    version = "$Default"
  }
}

Error Output

β•·
β”‚ Error: error waiting for Auto Scaling Group Capacity: "example": Waiting up to 10m0s: Need exactly 18 healthy instances in ASG, have 3. Most recent activity: {
β”‚   ActivityId: "49c921d0-0fc5-443d-970b-93a923963bc8",
β”‚   AutoScalingGroupARN: "arn:aws:autoscaling:us-east-1:<REDACTED>:autoScalingGroup:<REDACTED>:autoScalingGroupName/example",
β”‚   AutoScalingGroupName: "example",
β”‚   Cause: "At 2022-08-09T17:13:09Z a user request update of AutoScalingGroup constraints to min: 3, max: 6, desired: 3 changing the desired capacity from 18 to 3.  At 2022-08-09T17:13:21Z an instance was taken ou
t of service in response to a difference between desired and actual capacity, shrinking the capacity from 18 to 3.  At 2022-08-09T17:13:22Z instance i-06478114701149239 was selected for termination.  At 2022-08-09
T17:13:22Z instance i-0a548b7f987b087b6 was selected for termination.  At 2022-08-09T17:13:22Z instance i-0a6e2d29f3b07f9fd was selected for termination.  At 2022-08-09T17:13:22Z instance i-06e45723a65382d11 was s
elected for termination.  At 2022-08-09T17:13:22Z instance i-0b9699eae661df37d was selected for termination.  At 2022-08-09T17:13:22Z instance i-0abcdb537ab960bf2 was selected for termination.  At 2022-08-09T17:13
:23Z instance i-07305e86a0a1dd8b2 was selected for termination.  At 2022-08-09T17:13:23Z instance i-0cbeb5ea68c193c56 was selected for termination.  At 2022-08-09T17:13:23Z instance i-0b5f8a0c30af221a6 was selecte
d for termination.  At 2022-08-09T17:13:23Z instance i-09d7d8ba1a04dc2de was selected for termination.  At 2022-08-09T17:13:23Z instance i-0d65b220963f4f4b5 was selected for termination.  At 2022-08-09T17:13:23Z i
nstance i-0c4d6480b9aa87268 was selected for termination.  At 2022-08-09T17:13:24Z instance i-0e716c835d50de9cc was selected for termination.  At 2022-08-09T17:13:24Z instance i-0fbb5cfdc4aec8693 was selected for 
termination.  At 2022-08-09T17:13:24Z instance i-0c9329d16284c113e was selected for termination.",
β”‚   Description: "Terminating EC2 instance: i-0c9329d16284c113e",
β”‚   Details: "{\"Subnet ID\":\"subnet-<REDACTED>\",\"Availability Zone\":\"us-east-1d\"}",
β”‚   EndTime: 2022-08-09 17:14:27 +0000 UTC,
β”‚   Progress: 100,
β”‚   StartTime: 2022-08-09 17:13:24.517 +0000 UTC,
β”‚   StatusCode: "Successful"
β”‚ }
β”‚ 

Expected Behavior

If desired_capacity isn't in the terraform config, and is outside the range of the capacity, terraform should wait until the number of instances is within the range, not until it is exactly the desired_capacity.

Actual Behavior

when changing the capacity of the scale group, if there is a desired capacity in the state, even if it isn't set in the configuration, and is outside the range of the min and max size, terraform waits until the number of instances is exactly that desired capacity.

Steps to Reproduce

  1. Create a scalegroup with a high max_size and desired_capacity
  2. Make a change to the configuration to reduce max_size below the current desired_capacity , and remove the desired_capacity configuration
  3. try to apply

Important Factoids

If you do a plan after the failed apply, it says there are no changes.

github-actions[bot] commented 3 months ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

tmccombs commented 3 months ago

I'm still interested in this