Terraform-provider-aws: Error when OnDemandBaseCapacity is greater than 0 when auto scaling group is being created

Created on 21 Aug 2019  路  3Comments  路  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

  • Terraform v0.12.2
  • provider.aws v2.23.0
  • provider.template v2.1.2

Affected Resource(s)

  • aws_autoscaling_group

Terraform Configuration Files

resource "aws_launch_template" "webserver" {
  name_prefix            = "${var.environment_name}-web-"
  image_id               = data.aws_ami.web.id
  instance_type          = var.web_instance_priority_1


  lifecycle {
    create_before_destroy = true
  }
}


resource "aws_autoscaling_group" "webserver-scaling-group" {
  name = "asg-${aws_launch_template.webserver.id}-${aws_launch_template.webserver.latest_version}"

  vpc_zone_identifier = sort(data.aws_subnet_ids.private_subnets.ids)

  desired_capacity = 2
  min_size         = 2
  max_size         = 4

  mixed_instances_policy {
    launch_template {
      launch_template_specification {
        launch_template_id = aws_launch_template.webserver.id
        version            = "$Latest"
      }

      override {
        instance_type = var.web_instance_priority_1
      }

      override {
        instance_type = var.web_instance_priority_2
      }

      override {
        instance_type = var.web_instance_priority_3
      }

      override {
        instance_type = var.web_instance_priority_4
      }
    }

    instances_distribution {
      on_demand_base_capacity                  = 2
      on_demand_percentage_above_base_capacity = 0
    }
  }

  target_group_arns         = [aws_alb_target_group.web.arn]
  health_check_type         = "ELB"
  wait_for_elb_capacity     = 2
  wait_for_capacity_timeout = "15m"



  lifecycle {
    create_before_destroy = true
  }
}

Expected Behavior

When the launch template gets updated due to an AMI change, the auto scaling group should get destroyed and recreated successfully.

Actual Behavior

Receive the error below:

Error: Error creating AutoScaling Group: ValidationError: Max bound, 0, must be greater than or equal to OnDemandBaseCapacity, 2.
status code: 400, request id: e560b0d0-aa2d-11e9-af61-6f9caecbaf19

on main.tf line 482, in resource "aws_autoscaling_group" "webserver-scaling-group":
482: resource "aws_autoscaling_group" "webserver-scaling-group" {

Steps to Reproduce

  1. terraform apply

Important Factoids


When we used launch configurations, the ASG would get destroyed and recreated perfectly. We switched to launch templates in order to begin using the mixed instance policy, and that is when we started encountering this. Interestingly, if you set the on_demand_base_capacity to zero, it works fine.

References

  • #0000
needs-triage servicautoscaling servicec2

Most helpful comment

I'm getting this when I have a initial_lifecycle_hook in my ASG. Works fine without it.

All 3 comments

I'm getting this when I have a initial_lifecycle_hook in my ASG. Works fine without it.

While not directly related to this I just switched to a mix instance policy and now I get this exact error on scheduled scaling actions when I attempt to set min, max and desired to 0. If I get keep my ASG max value above or equal to the OnDemandBaseCapacity value it has no issues. So it's probably not a provider specific thing but an AWS API thing. Could probably just add some error checking to the provider for this particular scenario I guess?

Executing scheduled action ScaleDown. Status Reason: Max bound, 0, must be greater than or equal to OnDemandBaseCapacity, 1.

I think there's a similar post on the forum with a minimum repro: https://discuss.hashicorp.com/t/cannot-create-asg-with-mixed-instances-and-lifecycle-hooks/13400

Was this page helpful?
0 / 5 - 0 ratings