terraform-provider-aws: Error when OnDemandBaseCapacity is greater than 0 when auto scaling group is being created
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
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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 27
- Comments: 15 (3 by maintainers)
I’m getting this when I have a
initial_lifecycle_hookin my ASG. Works fine without it.@justinretzolk I can confirm this is still broken with
v1.0.11I can confirm that the issue goes away if I simply remove the lifecycle hook from the ASG. This still exists in Terraform v0.13.5 with AWS Provider v3.15.0. Can anyone take a look at this? It is quite inconvenient for our pipeline automation.